Skip to content

Commit

Permalink
functionally complete
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Apr 1, 2019
1 parent 6ee4bc0 commit 76ab1d7
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 67 deletions.
94 changes: 54 additions & 40 deletions app/src/main/java/co/tinode/tindroid/FindAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
.getSystemService(AppCompatActivity.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(viewType, parent, false);
switch (viewType) {
case R.layout.contact_empty:
case R.layout.not_found:
return new ViewHolderEmpty(view);
case R.layout.contact_section:
return new ViewHolderSection(view);
Expand All @@ -123,25 +123,31 @@ public int getItemViewType(int position) {
return R.layout.contact_section;
}

int count = getCursorItemCount() + 1;
if (count == 1) {
if (position == 1) {
position --;

int count = getCursorItemCount();
if (count == 0) {
if (position == 0) {
// The 'empty' element in the 'PHONE CONTACTS' section.
return R.layout.contact_empty;
return R.layout.not_found;
}
}

if (position < count) {
// One 'empty' element
count = 1;
} else if (position < count) {
return R.layout.contact;
}

if (position == count) {
position -= count;

if (position == 0) {
return R.layout.contact_section;
}

count ++;
if (getFoundItemCount() == 0 && position == count) {
return R.layout.contact_empty;
position --;

count = getFoundItemCount();
if (count == 0 && position == 0) {
return R.layout.not_found;
}

return R.layout.contact;
Expand All @@ -153,34 +159,42 @@ public long getItemId(int position) {
return "section_one".hashCode();
}

// Count the section title element.
int count = getCursorItemCount() + 1;
if (count == 1) {
if (position == 1) {
// Subtract section title.
position --;

int count = getCursorItemCount();
if (count == 0) {
if (position == 0) {
// The 'empty' element in the 'PHONE CONTACTS' section.
return "empty_one".hashCode();
}
}

if (position < count) {
count = 1;
} else if (position < count) {
// Element from the cursor.
mCursor.moveToPosition(position - 1);
mCursor.moveToPosition(position);
String unique = mCursor.getString(ContactsLoaderCallback.ContactsQuery.IM_ADDRESS);
return ("contact:" + unique).hashCode();
}

if (position == count) {
// Skip all cursor elements
position -= count;

if (position == 0) {
// Section title DIRECTORY;
return "section_two".hashCode();
}

count ++;
if (getFoundItemCount() == 0 && position == count) {
// Subtract section title.
position --;

count = getFoundItemCount();
if (count == 0 && position == 0) {
// The 'empty' element in the DIRECTORY section.
return "empty_two".hashCode();
}

return ("found:" + mFound.get(position - count).getUnique()).hashCode();
return ("found:" + mFound.get(position).getUnique()).hashCode();
}

private int getCursorItemCount() {
Expand All @@ -191,46 +205,46 @@ private int getFoundItemCount() {
return mFound.size();
}


private int getActualItemCount() {
return getCursorItemCount() + getFoundItemCount();
}

private Object getItemAt(int position) {
if (position == 0) {
// Section title 'PHONE CONTACTS';
return null;
}

position --;

// Count the section title element.
int count = getCursorItemCount() + 1;
if (count == 1) {
if (position == 1) {
int count = getCursorItemCount();
if (count == 0) {
if (position == 0) {
// The 'empty' element in the 'PHONE CONTACTS' section.
return null;
}
}

if (position < count) {
count = 1;
} else if (position < count) {
// One of the phone contacts. Move the cursor
// to the correct position and return it.
mCursor.moveToPosition(position - 1);
mCursor.moveToPosition(position);
return mCursor;
}

if (position == count) {
position -= count;

if (position == 0) {
// Section title DIRECTORY;
return null;
}

// Count the 'DIRECTORY' element;
count ++;
if (getFoundItemCount() == 0 && position == count) {
// Skip the 'DIRECTORY' element;
position --;

count = getFoundItemCount();
if (count == 0 && position == 0) {
// The 'empty' element in the DIRECTORY section.
return null;
}

return mFound.get(position - count);
return mFound.get(position);
}

@Override
Expand Down
26 changes: 9 additions & 17 deletions app/src/main/java/co/tinode/tindroid/StartChatActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public class StartChatActivity extends AppCompatActivity {
@SuppressWarnings("unused")
private static final String TAG = "StartChatActivity";

private static final int TAB_CONTACTS = 0;
private static final int COUNT_OF_TABS = 3;
private static final int TAB_SEARCH = 0;
private static final int TAB_NEW_GROUP = 1;
private static final int TAB_SEARCH = 2;
private static final int TAB_BY_ID = 3;
private static final int TAB_BY_ID = 2;


static {
Expand Down Expand Up @@ -106,11 +106,8 @@ public void onRequestPermissionsResult(int requestCode,
}

private class PagerAdapter extends FragmentStatePagerAdapter {
private static final int sNumOfTabs = 4;

Fragment mContacts;
Fragment mCreateGroup;
Fragment mSearch;
Fragment mCreateGroup;
Fragment mById;

PagerAdapter(FragmentManager fm) {
Expand All @@ -121,21 +118,16 @@ private class PagerAdapter extends FragmentStatePagerAdapter {
@NonNull
public Fragment getItem(int position) {
switch (position) {
case TAB_CONTACTS:
if (mContacts == null) {
mContacts = new ContactsFragment();
case TAB_SEARCH:
if (mSearch == null) {
mSearch = new FindFragment();
}
return mContacts;
return mSearch;
case TAB_NEW_GROUP:
if (mCreateGroup == null) {
mCreateGroup = new CreateGroupFragment();
}
return mCreateGroup;
case TAB_SEARCH:
if (mSearch == null) {
mSearch = new FindFragment();
}
return mSearch;
case TAB_BY_ID:
if (mById == null) {
mById = new AddByIDFragment();
Expand All @@ -148,7 +140,7 @@ public Fragment getItem(int position) {

@Override
public int getCount() {
return sNumOfTabs;
return COUNT_OF_TABS;
}
}
}
2 changes: 2 additions & 0 deletions app/src/main/java/co/tinode/tindroid/TopicInfoFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import androidx.fragment.app.Fragment;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.text.TextUtils;
Expand Down Expand Up @@ -85,6 +86,7 @@ public void onViewCreated(@NonNull View view, Bundle savedInstance) {

RecyclerView rv = view.findViewById(R.id.groupMembers);
rv.setLayoutManager(new LinearLayoutManager(activity, RecyclerView.VERTICAL, false));
rv.addItemDecoration(new DividerItemDecoration(activity, DividerItemDecoration.VERTICAL));
rv.setAdapter(mAdapter);
rv.setNestedScrollingEnabled(false);

Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/layout/not_found.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="?attr/listPreferredItemHeight"
android:gravity="center"
android:text="@string/no_results"
android:textAppearance="?android:attr/textAppearanceMedium" />
13 changes: 3 additions & 10 deletions app/src/main/res/layout/toolbar_with_tabs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,20 @@
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabsContacts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable">
android:layout_height="wrap_content">

<com.google.android.material.tabs.TabItem
android:id="@+id/tab_contacts"
android:id="@+id/tab_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/contacts"/>
android:text="@string/find"/>

<com.google.android.material.tabs.TabItem
android:id="@+id/tab_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/group"/>

<com.google.android.material.tabs.TabItem
android:id="@+id/tab_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/find"/>

<com.google.android.material.tabs.TabItem
android:id="@+id/tab_by_id"
android:layout_width="wrap_content"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,5 @@
<string name="hint_search_tags">Поиск по тагам</string>
<string name="contacts_section_contacts">Адресная книга</string>
<string name="contacts_section_directory">Глобальная Директория</string>
<string name="no_results">Ничего не найдено</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,6 @@
<string name="group">Group</string>
<string name="id_required">ID is required</string>
<string name="settings">Settings</string>
<string name="no_results">No results</string>

</resources>

0 comments on commit 76ab1d7

Please sign in to comment.