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. 39
      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

39
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 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_URL;
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);
}
subBoardViewHolder.boardRow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
subBoardViewHolder.boardRow.setOnClickListener(view -> {
Intent intent = new Intent(context, BoardActivity.class);
Bundle extras = new Bundle();
extras.putString(BUNDLE_BOARD_URL, subBoard.getUrl());
extras.putString(BUNDLE_BOARD_TITLE, subBoard.getTitle());
intent.putExtras(extras);
intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
});
if (boardExpandableVisibility.get(subBoardViewHolder.getAdapterPosition() - 1)) {
subBoardViewHolder.boardExpandable.setVisibility(View.VISIBLE);
@ -152,9 +148,7 @@ class BoardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
subBoardViewHolder.boardExpandable.setVisibility(View.GONE);
subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp);
}
subBoardViewHolder.showHideExpandable.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
subBoardViewHolder.showHideExpandable.setOnClickListener(view -> {
final boolean visible = boardExpandableVisibility.get(subBoardViewHolder.getAdapterPosition() - 1);
if (visible) {
subBoardViewHolder.boardExpandable.setVisibility(View.GONE);
@ -164,24 +158,20 @@ class BoardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
subBoardViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_up_accent_24dp);
}
boardExpandableVisibility.set(subBoardViewHolder.getAdapterPosition() - 1, !visible);
}
});
subBoardViewHolder.boardTitle.setText(subBoard.getTitle());
subBoardViewHolder.boardMods.setText(subBoard.getMods());
subBoardViewHolder.boardStats.setText(subBoard.getStats());
subBoardViewHolder.boardLastPost.setText(subBoard.getLastPost());
if (!Objects.equals(subBoard.getLastPostUrl(), "")) {
subBoardViewHolder.boardLastPost.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
subBoardViewHolder.boardLastPost.setOnClickListener(view -> {
Intent intent = new Intent(context, TopicActivity.class);
Bundle extras = new Bundle();
extras.putString(BUNDLE_TOPIC_URL, subBoard.getLastPostUrl());
//Doesn't put an already ellipsized topic title in Bundle
intent.putExtras(extras);
intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(intent);
}
});
}
} else if (holder instanceof TopicViewHolder) {
@ -193,17 +183,14 @@ class BoardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
topicExpandableVisibility.add(false);
}
topicViewHolder.topicRow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
topicViewHolder.topicRow.setOnClickListener(view -> {
Intent intent = new Intent(context, TopicActivity.class);
Bundle extras = new Bundle();
extras.putString(BUNDLE_TOPIC_URL, topic.getUrl());
extras.putString(BUNDLE_TOPIC_TITLE, topic.getSubject());
intent.putExtras(extras);
intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(intent);
}
});
if (topicExpandableVisibility.get(topicViewHolder.getAdapterPosition() - parsedSubBoards
.size() - 2)) {
@ -213,9 +200,7 @@ class BoardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
topicViewHolder.topicExpandable.setVisibility(View.GONE);
topicViewHolder.showHideExpandable.setImageResource(R.drawable.ic_arrow_drop_down_accent_24dp);
}
topicViewHolder.showHideExpandable.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
topicViewHolder.showHideExpandable.setOnClickListener(view -> {
final boolean visible = topicExpandableVisibility.get(topicViewHolder.
getAdapterPosition() - parsedSubBoards.size() - 2);
if (visible) {
@ -227,7 +212,6 @@ class BoardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
}
topicExpandableVisibility.set(topicViewHolder.getAdapterPosition() -
parsedSubBoards.size() - 2, !visible);
}
});
topicViewHolder.topicSubject.setTypeface(Typeface.createFromAsset(context.getAssets()
, "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.topicStats.setText(topic.getStats());
topicViewHolder.topicLastPost.setText(context.getString(R.string.topic_last_post, topic.getLastPostDateAndTime()));
topicViewHolder.topicLastPost.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
topicViewHolder.topicLastPost.setOnClickListener(view -> {
Intent intent = new Intent(context, TopicActivity.class);
Bundle extras = new Bundle();
extras.putString(BUNDLE_TOPIC_URL, topic.getLastPostUrl());
//Doesn't put an already ellipsized topic title in Bundle
intent.putExtras(extras);
intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(intent);
}
});
} else if (holder instanceof LoadingViewHolder) {
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);
i.putExtra(BUNDLE_TOPIC_URL, topicSummary.getTopicUrl());
i.putExtra(BUNDLE_TOPIC_TITLE, topicSummary.getSubject());
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(i);
}
@ -156,6 +157,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
Intent i = new Intent(MainActivity.this, TopicActivity.class);
i.putExtra(BUNDLE_TOPIC_URL, topicSummary.getTopicUrl());
i.putExtra(BUNDLE_TOPIC_TITLE, topicSummary.getSubject());
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(i);
} else
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)
.icon(FontAwesome.Icon.faw_user)
.paddingDp(10)
.color(ContextCompat.getColor(this, R.color.primary_light))
.backgroundColor(ContextCompat.getColor(this, R.color.primary)));
.color(ContextCompat.getColor(this, R.color.iron))
.backgroundColor(ContextCompat.getColor(this, R.color.primary_light)));
}
//-------------------------------------------LOGOUT-------------------------------------------------

4
build.gradle

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

Loading…
Cancel
Save