Browse Source

Hopefully prevent multiple TopicActivities from spawning simultaneously (RecentFragment, UnreadFragment)

pull/61/merge
Ezerous 6 years ago
parent
commit
8605b9b4c1
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 123
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java
  2. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java
  3. 4
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
  4. 4
      build.gradle

123
app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardAdapter.java

@ -22,7 +22,6 @@ import gr.thmmy.mthmmy.model.Board;
import gr.thmmy.mthmmy.model.Topic; import gr.thmmy.mthmmy.model.Topic;
import me.zhanghai.android.materialprogressbar.MaterialProgressBar; import me.zhanghai.android.materialprogressbar.MaterialProgressBar;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE; import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE;
import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL; import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL;
import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE; import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE;
@ -133,17 +132,14 @@ class BoardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
boardExpandableVisibility.add(false); boardExpandableVisibility.add(false);
} }
subBoardViewHolder.boardRow.setOnClickListener(new View.OnClickListener() { subBoardViewHolder.boardRow.setOnClickListener(view -> {
@Override Intent intent = new Intent(context, BoardActivity.class);
public void onClick(View view) { Bundle extras = new Bundle();
Intent intent = new Intent(context, BoardActivity.class); extras.putString(BUNDLE_BOARD_URL, subBoard.getUrl());
Bundle extras = new Bundle(); extras.putString(BUNDLE_BOARD_TITLE, subBoard.getTitle());
extras.putString(BUNDLE_BOARD_URL, subBoard.getUrl()); intent.putExtras(extras);
extras.putString(BUNDLE_BOARD_TITLE, subBoard.getTitle()); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtras(extras); context.startActivity(intent);
intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}); });
if (boardExpandableVisibility.get(subBoardViewHolder.getAdapterPosition() - 1)) { if (boardExpandableVisibility.get(subBoardViewHolder.getAdapterPosition() - 1)) {
subBoardViewHolder.boardExpandable.setVisibility(View.VISIBLE); subBoardViewHolder.boardExpandable.setVisibility(View.VISIBLE);
@ -152,36 +148,30 @@ class BoardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
subBoardViewHolder.boardExpandable.setVisibility(View.GONE); subBoardViewHolder.boardExpandable.setVisibility(View.GONE);
subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp); subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp);
} }
subBoardViewHolder.showHideExpandable.setOnClickListener(new View.OnClickListener() { subBoardViewHolder.showHideExpandable.setOnClickListener(view -> {
@Override final boolean visible = boardExpandableVisibility.get(subBoardViewHolder.getAdapterPosition() - 1);
public void onClick(View view) { if (visible) {
final boolean visible = boardExpandableVisibility.get(subBoardViewHolder.getAdapterPosition() - 1); subBoardViewHolder.boardExpandable.setVisibility(View.GONE);
if (visible) { subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp);
subBoardViewHolder.boardExpandable.setVisibility(View.GONE); } else {
subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp); subBoardViewHolder.boardExpandable.setVisibility(View.VISIBLE);
} else { subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp);
subBoardViewHolder.boardExpandable.setVisibility(View.VISIBLE);
subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp);
}
boardExpandableVisibility.set(subBoardViewHolder.getAdapterPosition() - 1, !visible);
} }
boardExpandableVisibility.set(subBoardViewHolder.getAdapterPosition() - 1, !visible);
}); });
subBoardViewHolder.boardTitle.setText(subBoard.getTitle()); subBoardViewHolder.boardTitle.setText(subBoard.getTitle());
subBoardViewHolder.boardMods.setText(subBoard.getMods()); subBoardViewHolder.boardMods.setText(subBoard.getMods());
subBoardViewHolder.boardStats.setText(subBoard.getStats()); subBoardViewHolder.boardStats.setText(subBoard.getStats());
subBoardViewHolder.boardLastPost.setText(subBoard.getLastPost()); subBoardViewHolder.boardLastPost.setText(subBoard.getLastPost());
if (!Objects.equals(subBoard.getLastPostUrl(), "")) { if (!Objects.equals(subBoard.getLastPostUrl(), "")) {
subBoardViewHolder.boardLastPost.setOnClickListener(new View.OnClickListener() { subBoardViewHolder.boardLastPost.setOnClickListener(view -> {
@Override Intent intent = new Intent(context, TopicActivity.class);
public void onClick(View view) { Bundle extras = new Bundle();
Intent intent = new Intent(context, TopicActivity.class); extras.putString(BUNDLE_TOPIC_URL, subBoard.getLastPostUrl());
Bundle extras = new Bundle(); //Doesn't put an already ellipsized topic title in Bundle
extras.putString(BUNDLE_TOPIC_URL, subBoard.getLastPostUrl()); intent.putExtras(extras);
//Doesn't put an already ellipsized topic title in Bundle intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtras(extras); context.startActivity(intent);
intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}); });
} }
} else if (holder instanceof TopicViewHolder) { } else if (holder instanceof TopicViewHolder) {
@ -193,17 +183,14 @@ class BoardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
topicExpandableVisibility.add(false); topicExpandableVisibility.add(false);
} }
topicViewHolder.topicRow.setOnClickListener(new View.OnClickListener() { topicViewHolder.topicRow.setOnClickListener(view -> {
@Override Intent intent = new Intent(context, TopicActivity.class);
public void onClick(View view) { Bundle extras = new Bundle();
Intent intent = new Intent(context, TopicActivity.class); extras.putString(BUNDLE_TOPIC_URL, topic.getUrl());
Bundle extras = new Bundle(); extras.putString(BUNDLE_TOPIC_TITLE, topic.getSubject());
extras.putString(BUNDLE_TOPIC_URL, topic.getUrl()); intent.putExtras(extras);
extras.putString(BUNDLE_TOPIC_TITLE, topic.getSubject()); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtras(extras); context.startActivity(intent);
intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}); });
if (topicExpandableVisibility.get(topicViewHolder.getAdapterPosition() - parsedSubBoards if (topicExpandableVisibility.get(topicViewHolder.getAdapterPosition() - parsedSubBoards
.size() - 2)) { .size() - 2)) {
@ -213,21 +200,18 @@ class BoardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
topicViewHolder.topicExpandable.setVisibility(View.GONE); topicViewHolder.topicExpandable.setVisibility(View.GONE);
topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp); topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp);
} }
topicViewHolder.showHideExpandable.setOnClickListener(new View.OnClickListener() { topicViewHolder.showHideExpandable.setOnClickListener(view -> {
@Override final boolean visible = topicExpandableVisibility.get(topicViewHolder.
public void onClick(View view) { getAdapterPosition() - parsedSubBoards.size() - 2);
final boolean visible = topicExpandableVisibility.get(topicViewHolder. if (visible) {
getAdapterPosition() - parsedSubBoards.size() - 2); topicViewHolder.topicExpandable.setVisibility(View.GONE);
if (visible) { topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp);
topicViewHolder.topicExpandable.setVisibility(View.GONE); } else {
topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp); topicViewHolder.topicExpandable.setVisibility(View.VISIBLE);
} else { topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp);
topicViewHolder.topicExpandable.setVisibility(View.VISIBLE);
topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp);
}
topicExpandableVisibility.set(topicViewHolder.getAdapterPosition() -
parsedSubBoards.size() - 2, !visible);
} }
topicExpandableVisibility.set(topicViewHolder.getAdapterPosition() -
parsedSubBoards.size() - 2, !visible);
}); });
topicViewHolder.topicSubject.setTypeface(Typeface.createFromAsset(context.getAssets() topicViewHolder.topicSubject.setTypeface(Typeface.createFromAsset(context.getAssets()
, "fonts/fontawesome-webfont.ttf")); , "fonts/fontawesome-webfont.ttf"));
@ -248,17 +232,14 @@ class BoardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
topicViewHolder.topicStartedBy.setText(context.getString(R.string.topic_started_by, topic.getStarter())); topicViewHolder.topicStartedBy.setText(context.getString(R.string.topic_started_by, topic.getStarter()));
topicViewHolder.topicStats.setText(topic.getStats()); topicViewHolder.topicStats.setText(topic.getStats());
topicViewHolder.topicLastPost.setText(context.getString(R.string.topic_last_post, topic.getLastPostDateAndTime())); topicViewHolder.topicLastPost.setText(context.getString(R.string.topic_last_post, topic.getLastPostDateAndTime()));
topicViewHolder.topicLastPost.setOnClickListener(new View.OnClickListener() { topicViewHolder.topicLastPost.setOnClickListener(view -> {
@Override Intent intent = new Intent(context, TopicActivity.class);
public void onClick(View view) { Bundle extras = new Bundle();
Intent intent = new Intent(context, TopicActivity.class); extras.putString(BUNDLE_TOPIC_URL, topic.getLastPostUrl());
Bundle extras = new Bundle(); //Doesn't put an already ellipsized topic title in Bundle
extras.putString(BUNDLE_TOPIC_URL, topic.getLastPostUrl()); intent.putExtras(extras);
//Doesn't put an already ellipsized topic title in Bundle intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtras(extras); context.startActivity(intent);
intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}); });
} else if (holder instanceof LoadingViewHolder) { } else if (holder instanceof LoadingViewHolder) {
LoadingViewHolder loadingViewHolder = (LoadingViewHolder) holder; LoadingViewHolder loadingViewHolder = (LoadingViewHolder) holder;

2
app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java

@ -139,6 +139,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
Intent i = new Intent(MainActivity.this, TopicActivity.class); Intent i = new Intent(MainActivity.this, TopicActivity.class);
i.putExtra(BUNDLE_TOPIC_URL, topicSummary.getTopicUrl()); i.putExtra(BUNDLE_TOPIC_URL, topicSummary.getTopicUrl());
i.putExtra(BUNDLE_TOPIC_TITLE, topicSummary.getSubject()); i.putExtra(BUNDLE_TOPIC_TITLE, topicSummary.getSubject());
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(i); startActivity(i);
} }
@ -156,6 +157,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
Intent i = new Intent(MainActivity.this, TopicActivity.class); Intent i = new Intent(MainActivity.this, TopicActivity.class);
i.putExtra(BUNDLE_TOPIC_URL, topicSummary.getTopicUrl()); i.putExtra(BUNDLE_TOPIC_URL, topicSummary.getTopicUrl());
i.putExtra(BUNDLE_TOPIC_TITLE, topicSummary.getSubject()); i.putExtra(BUNDLE_TOPIC_TITLE, topicSummary.getSubject());
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(i); startActivity(i);
} else } else
Timber.e("onUnreadFragmentInteraction TopicSummary came without a link"); Timber.e("onUnreadFragmentInteraction TopicSummary came without a link");

4
app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java

@ -457,8 +457,8 @@ public abstract class BaseActivity extends AppCompatActivity {
profileDrawerItem.withIcon(new IconicsDrawable(this) profileDrawerItem.withIcon(new IconicsDrawable(this)
.icon(FontAwesome.Icon.faw_user) .icon(FontAwesome.Icon.faw_user)
.paddingDp(10) .paddingDp(10)
.color(ContextCompat.getColor(this, R.color.primary_light)) .color(ContextCompat.getColor(this, R.color.iron))
.backgroundColor(ContextCompat.getColor(this, R.color.primary))); .backgroundColor(ContextCompat.getColor(this, R.color.primary_light)));
} }
//-------------------------------------------LOGOUT------------------------------------------------- //-------------------------------------------LOGOUT-------------------------------------------------

4
build.gradle

@ -2,10 +2,10 @@
buildscript { buildscript {
repositories { repositories {
jcenter()
maven { url "https://jitpack.io" } maven { url "https://jitpack.io" }
maven { url "https://maven.fabric.io/public" } maven { url "https://maven.fabric.io/public" }
google() google()
jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.2.1' classpath 'com.android.tools.build:gradle:3.2.1'
@ -17,9 +17,9 @@ buildscript {
allprojects { allprojects {
repositories { repositories {
jcenter()
maven { url "https://jitpack.io" } maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" } maven { url "https://maven.google.com" }
jcenter()
} }
} }

Loading…
Cancel
Save