diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f64a62ed..47ceb60c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -82,7 +82,9 @@ - + diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java index c43b85e3..a4a200bd 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.java @@ -75,6 +75,15 @@ import retrofit2.Response; public class MainActivity extends BaseActivity { private static final String TAG = "MainActivity"; // logging tag protected static int COMPOSE_RESULT = 1; + private static final long DRAWER_ITEM_EDIT_PROFILE = 0; + private static final long DRAWER_ITEM_FAVOURITES = 1; + private static final long DRAWER_ITEM_MUTED_USERS = 2; + private static final long DRAWER_ITEM_BLOCKED_USERS = 3; + private static final long DRAWER_ITEM_SEARCH = 4; + private static final long DRAWER_ITEM_PREFERENCES = 5; + private static final long DRAWER_ITEM_ABOUT = 6; + private static final long DRAWER_ITEM_LOG_OUT = 7; + private static final long DRAWER_ITEM_FOLLOW_REQUESTS = 8; private String loggedInAccountId; private String loggedInAccountUsername; @@ -289,15 +298,15 @@ public class MainActivity extends BaseActivity { .withHasStableIds(true) .withSelectedItem(-1) .addDrawerItems( - new PrimaryDrawerItem().withIdentifier(0).withName(getString(R.string.action_edit_profile)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_person), - new PrimaryDrawerItem().withIdentifier(1).withName(getString(R.string.action_view_favourites)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_star), - new PrimaryDrawerItem().withIdentifier(2).withName(getString(R.string.action_view_mutes)).withSelectable(false).withIcon(muteDrawable), - new PrimaryDrawerItem().withIdentifier(3).withName(getString(R.string.action_view_blocks)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_block), - new PrimaryDrawerItem().withIdentifier(4).withName(getString(R.string.action_search)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_search), + new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_EDIT_PROFILE).withName(getString(R.string.action_edit_profile)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_person), + new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_FAVOURITES).withName(getString(R.string.action_view_favourites)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_star), + new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_MUTED_USERS).withName(getString(R.string.action_view_mutes)).withSelectable(false).withIcon(muteDrawable), + new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_BLOCKED_USERS).withName(getString(R.string.action_view_blocks)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_block), + new PrimaryDrawerItem().withIdentifier(DRAWER_ITEM_SEARCH).withName(getString(R.string.action_search)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_search), new DividerDrawerItem(), - new SecondaryDrawerItem().withIdentifier(5).withName(getString(R.string.action_view_preferences)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_settings), - new SecondaryDrawerItem().withIdentifier(6).withName(getString(R.string.about_title_activity)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_info), - new SecondaryDrawerItem().withIdentifier(7).withName(getString(R.string.action_logout)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_exit_to_app) + new SecondaryDrawerItem().withIdentifier(DRAWER_ITEM_PREFERENCES).withName(getString(R.string.action_view_preferences)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_settings), + new SecondaryDrawerItem().withIdentifier(DRAWER_ITEM_ABOUT).withName(getString(R.string.about_title_activity)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_info), + new SecondaryDrawerItem().withIdentifier(DRAWER_ITEM_LOG_OUT).withName(getString(R.string.action_logout)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_exit_to_app) ) .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { @Override @@ -305,32 +314,32 @@ public class MainActivity extends BaseActivity { if (drawerItem != null) { long drawerItemIdentifier = drawerItem.getIdentifier(); - if (drawerItemIdentifier == 0) { + if (drawerItemIdentifier == DRAWER_ITEM_EDIT_PROFILE) { Intent intent = new Intent(MainActivity.this, EditProfileActivity.class); startActivity(intent); - } else if (drawerItemIdentifier == 1) { + } else if (drawerItemIdentifier == DRAWER_ITEM_FAVOURITES) { Intent intent = new Intent(MainActivity.this, FavouritesActivity.class); startActivity(intent); - } else if (drawerItemIdentifier == 2) { + } else if (drawerItemIdentifier == DRAWER_ITEM_MUTED_USERS) { Intent intent = new Intent(MainActivity.this, AccountListActivity.class); intent.putExtra("type", AccountListActivity.Type.MUTES); startActivity(intent); - } else if (drawerItemIdentifier == 3) { + } else if (drawerItemIdentifier == DRAWER_ITEM_BLOCKED_USERS) { Intent intent = new Intent(MainActivity.this, AccountListActivity.class); intent.putExtra("type", AccountListActivity.Type.BLOCKS); startActivity(intent); - } else if (drawerItemIdentifier == 4) { + } else if (drawerItemIdentifier == DRAWER_ITEM_SEARCH) { Intent intent = new Intent(MainActivity.this, SearchActivity.class); startActivity(intent); - } else if (drawerItemIdentifier == 5) { + } else if (drawerItemIdentifier == DRAWER_ITEM_PREFERENCES) { Intent intent = new Intent(MainActivity.this, PreferencesActivity.class); startActivity(intent); - } else if (drawerItemIdentifier == 6) { + } else if (drawerItemIdentifier == DRAWER_ITEM_ABOUT) { Intent intent = new Intent(MainActivity.this, AboutActivity.class); startActivity(intent); - } else if (drawerItemIdentifier == 7) { + } else if (drawerItemIdentifier == DRAWER_ITEM_LOG_OUT) { logout(); - } else if (drawerItemIdentifier == 8) { + } else if (drawerItemIdentifier == DRAWER_ITEM_FOLLOW_REQUESTS) { Intent intent = new Intent(MainActivity.this, AccountListActivity.class); intent.putExtra("type", AccountListActivity.Type.FOLLOW_REQUESTS); startActivity(intent); @@ -516,7 +525,7 @@ public class MainActivity extends BaseActivity { // Show follow requests in the menu, if this is a locked account. if (me.locked) { PrimaryDrawerItem followRequestsItem = new PrimaryDrawerItem() - .withIdentifier(8) + .withIdentifier(DRAWER_ITEM_FOLLOW_REQUESTS) .withName(R.string.action_view_follow_requests) .withSelectable(false) .withIcon(GoogleMaterial.Icon.gmd_person_add); diff --git a/app/src/main/java/com/keylesspalace/tusky/SearchActivity.java b/app/src/main/java/com/keylesspalace/tusky/SearchActivity.java index 9b30c957..2b8a9be7 100644 --- a/app/src/main/java/com/keylesspalace/tusky/SearchActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/SearchActivity.java @@ -35,20 +35,20 @@ import android.widget.TextView; import com.keylesspalace.tusky.adapter.SearchResultsAdapter; import com.keylesspalace.tusky.entity.SearchResults; +import com.keylesspalace.tusky.interfaces.LinkListener; import java.util.List; -import butterknife.BindView; -import butterknife.ButterKnife; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; -public class SearchActivity extends BaseActivity implements SearchView.OnQueryTextListener { +public class SearchActivity extends BaseActivity implements SearchView.OnQueryTextListener, + LinkListener { private static final String TAG = "SearchActivity"; // logging tag - @BindView(R.id.progress_bar) ProgressBar progressBar; - @BindView(R.id.message_no_results) TextView messageNoResults; + private ProgressBar progressBar; + private TextView messageNoResults; private SearchResultsAdapter adapter; private String currentQuery; @@ -56,7 +56,9 @@ public class SearchActivity extends BaseActivity implements SearchView.OnQueryTe protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search); - ButterKnife.bind(this); + + progressBar = (ProgressBar) findViewById(R.id.progress_bar); + messageNoResults = (TextView) findViewById(R.id.message_no_results); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); @@ -69,7 +71,7 @@ public class SearchActivity extends BaseActivity implements SearchView.OnQueryTe RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view); recyclerView.setHasFixedSize(true); recyclerView.setLayoutManager(new LinearLayoutManager(this)); - adapter = new SearchResultsAdapter(); + adapter = new SearchResultsAdapter(this); recyclerView.setAdapter(adapter); handleIntent(getIntent()); @@ -117,6 +119,20 @@ public class SearchActivity extends BaseActivity implements SearchView.OnQueryTe return false; } + @Override + public void onViewAccount(String id) { + Intent intent = new Intent(this, AccountActivity.class); + intent.putExtra("id", id); + startActivity(intent); + } + + @Override + public void onViewTag(String tag) { + Intent intent = new Intent(this, ViewTagActivity.class); + intent.putExtra("hashtag", tag); + startActivity(intent); + } + private void handleIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { currentQuery = intent.getStringExtra(SearchManager.QUERY); diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/AccountViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/adapter/AccountViewHolder.java index c169841d..6c197e27 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/AccountViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/AccountViewHolder.java @@ -8,6 +8,7 @@ import android.widget.TextView; import com.keylesspalace.tusky.R; import com.keylesspalace.tusky.entity.Account; import com.keylesspalace.tusky.interfaces.AccountActionListener; +import com.keylesspalace.tusky.interfaces.LinkListener; import com.pkmmte.view.CircularImageView; import com.squareup.picasso.Picasso; @@ -48,4 +49,13 @@ class AccountViewHolder extends RecyclerView.ViewHolder { } }); } + + void setupLinkListener(final LinkListener listener) { + container.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + listener.onViewAccount(id); + } + }); + } } \ No newline at end of file diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/SearchResultsAdapter.java b/app/src/main/java/com/keylesspalace/tusky/adapter/SearchResultsAdapter.java index 6020944b..25f44e18 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/SearchResultsAdapter.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/SearchResultsAdapter.java @@ -24,6 +24,7 @@ import android.widget.TextView; import com.keylesspalace.tusky.R; import com.keylesspalace.tusky.entity.Account; import com.keylesspalace.tusky.entity.SearchResults; +import com.keylesspalace.tusky.interfaces.LinkListener; import java.util.ArrayList; import java.util.Arrays; @@ -35,11 +36,13 @@ public class SearchResultsAdapter extends RecyclerView.Adapter { private List accountList; private List hashtagList; + private LinkListener linkListener; - public SearchResultsAdapter() { + public SearchResultsAdapter(LinkListener listener) { super(); accountList = new ArrayList<>(); hashtagList = new ArrayList<>(); + linkListener = listener; } @Override @@ -64,10 +67,11 @@ public class SearchResultsAdapter extends RecyclerView.Adapter { if (position < accountList.size()) { AccountViewHolder holder = (AccountViewHolder) viewHolder; holder.setupWithAccount(accountList.get(position)); + holder.setupLinkListener(linkListener); } else { HashtagViewHolder holder = (HashtagViewHolder) viewHolder; int index = position - accountList.size(); - holder.setHashtag(hashtagList.get(index)); + holder.setup(hashtagList.get(index), linkListener); } } @@ -108,8 +112,14 @@ public class SearchResultsAdapter extends RecyclerView.Adapter { hashtag = (TextView) itemView.findViewById(R.id.hashtag); } - void setHashtag(String tag) { + void setup(final String tag, final LinkListener listener) { hashtag.setText(String.format("#%s", tag)); + hashtag.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + listener.onViewTag(tag); + } + }); } } } diff --git a/app/src/main/res/layout/item_hashtag.xml b/app/src/main/res/layout/item_hashtag.xml index 128b55df..baf4bd4c 100644 --- a/app/src/main/res/layout/item_hashtag.xml +++ b/app/src/main/res/layout/item_hashtag.xml @@ -1,7 +1,7 @@ + android:padding="16dp" />