Skip to content

Commit

Permalink
[Refactor] Use FragmentFinishable.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanghai committed Mar 31, 2018
1 parent 33813d8 commit 4050685
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
import android.support.v7.app.AppCompatActivity;

import me.zhanghai.android.douya.network.api.info.frodo.Broadcast;
import me.zhanghai.android.douya.ui.FragmentFinishable;
import me.zhanghai.android.douya.util.FragmentUtils;
import me.zhanghai.android.douya.util.TransitionUtils;

public class BroadcastActivity extends AppCompatActivity {
public class BroadcastActivity extends AppCompatActivity implements FragmentFinishable {

private static final String KEY_PREFIX = BroadcastActivity.class.getName() + '.';

Expand Down Expand Up @@ -88,11 +89,13 @@ public void finishAfterTransition() {
super.finishAfterTransition();
}

@Override
public void finishFromFragment() {
mShouldFinish = true;
super.finish();
}

@Override
public void finishAfterTransitionFromFragment() {
mShouldFinish = true;
super.supportFinishAfterTransition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import me.zhanghai.android.douya.settings.info.Settings;
import me.zhanghai.android.douya.ui.ConfirmDiscardContentDialogFragment;
import me.zhanghai.android.douya.ui.DoubleClickToolbar;
import me.zhanghai.android.douya.ui.FragmentFinishable;
import me.zhanghai.android.douya.ui.GetOnLongClickListenerImageButton;
import me.zhanghai.android.douya.ui.LoadMoreAdapter;
import me.zhanghai.android.douya.ui.NoChangeAnimationItemAnimator;
Expand Down Expand Up @@ -592,12 +593,10 @@ public void discardContent() {
}

private void finish() {
BroadcastActivity activity = (BroadcastActivity) getActivity();
activity.finishFromFragment();
FragmentFinishable.finish(getActivity());
}

private void finishAfterTransition() {
BroadcastActivity activity = (BroadcastActivity) getActivity();
activity.finishAfterTransitionFromFragment();
FragmentFinishable.finishAfterTransition(getActivity());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
import android.support.v7.app.AppCompatActivity;

import me.zhanghai.android.douya.network.api.info.frodo.Broadcast;
import me.zhanghai.android.douya.ui.FragmentFinishable;
import me.zhanghai.android.douya.util.FragmentUtils;

public class RebroadcastBroadcastActivity extends AppCompatActivity {
public class RebroadcastBroadcastActivity extends AppCompatActivity implements FragmentFinishable {

private static final String KEY_PREFIX = RebroadcastBroadcastActivity.class.getName() + '.';

Expand Down Expand Up @@ -77,11 +78,13 @@ public void finishAfterTransition() {
super.finishAfterTransition();
}

@Override
public void finishFromFragment() {
mShouldFinish = true;
super.finish();
}

@Override
public void finishAfterTransitionFromFragment() {
mShouldFinish = true;
super.supportFinishAfterTransition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import me.zhanghai.android.douya.network.api.ApiError;
import me.zhanghai.android.douya.network.api.info.frodo.Broadcast;
import me.zhanghai.android.douya.ui.ConfirmDiscardContentDialogFragment;
import me.zhanghai.android.douya.ui.FragmentFinishable;
import me.zhanghai.android.douya.util.FragmentUtils;
import me.zhanghai.android.douya.util.LogUtils;
import me.zhanghai.android.douya.util.ToastUtils;
Expand Down Expand Up @@ -286,12 +287,6 @@ public void discardContent() {
}

private void finish() {
RebroadcastBroadcastActivity activity = (RebroadcastBroadcastActivity) getActivity();
activity.finishFromFragment();
}

private void finishAfterTransition() {
RebroadcastBroadcastActivity activity = (RebroadcastBroadcastActivity) getActivity();
activity.finishAfterTransitionFromFragment();
FragmentFinishable.finish(getActivity());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
import java.util.ArrayList;
import java.util.List;

import me.zhanghai.android.douya.ui.FragmentFinishable;
import me.zhanghai.android.douya.util.DoubanUtils;
import me.zhanghai.android.douya.util.FragmentUtils;
import me.zhanghai.android.douya.util.ObjectUtils;
import me.zhanghai.android.douya.util.UrlUtils;

public class SendBroadcastActivity extends AppCompatActivity {
public class SendBroadcastActivity extends AppCompatActivity implements FragmentFinishable {

private static final String KEY_PREFIX = SendBroadcastActivity.class.getName() + '.';

Expand Down Expand Up @@ -127,11 +128,13 @@ public void finishAfterTransition() {
super.finishAfterTransition();
}

@Override
public void finishFromFragment() {
mShouldFinish = true;
super.finish();
}

@Override
public void finishAfterTransitionFromFragment() {
mShouldFinish = true;
super.supportFinishAfterTransition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import me.zhanghai.android.douya.eventbus.EventBusUtils;
import me.zhanghai.android.douya.network.api.info.frodo.Broadcast;
import me.zhanghai.android.douya.ui.ConfirmDiscardContentDialogFragment;
import me.zhanghai.android.douya.ui.FragmentFinishable;
import me.zhanghai.android.douya.util.AppUtils;
import me.zhanghai.android.douya.util.DoubanUtils;
import me.zhanghai.android.douya.util.FileUtils;
Expand Down Expand Up @@ -551,13 +552,7 @@ public void discardContent() {
}

private void finish() {
SendBroadcastActivity activity = (SendBroadcastActivity) getActivity();
activity.finishFromFragment();
}

private void finishAfterTransition() {
SendBroadcastActivity activity = (SendBroadcastActivity) getActivity();
activity.finishAfterTransitionFromFragment();
FragmentFinishable.finish(getActivity());
}

public static class LinkInfo implements Parcelable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import me.zhanghai.android.douya.ui.FragmentFinishable;
import me.zhanghai.android.douya.util.FragmentUtils;

public class SendCommentActivity extends AppCompatActivity {
public class SendCommentActivity extends AppCompatActivity implements FragmentFinishable {

private static final String KEY_PREFIX = SendCommentActivity.class.getName() + '.';

Expand Down Expand Up @@ -69,11 +70,13 @@ public void finishAfterTransition() {
super.finishAfterTransition();
}

@Override
public void finishFromFragment() {
mShouldFinish = true;
super.finish();
}

@Override
public void finishAfterTransitionFromFragment() {
mShouldFinish = true;
super.supportFinishAfterTransition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import me.zhanghai.android.douya.eventbus.BroadcastCommentSentEvent;
import me.zhanghai.android.douya.eventbus.EventBusUtils;
import me.zhanghai.android.douya.ui.ConfirmDiscardContentDialogFragment;
import me.zhanghai.android.douya.ui.FragmentFinishable;
import me.zhanghai.android.douya.util.FragmentUtils;
import me.zhanghai.android.douya.util.ToastUtils;

Expand Down Expand Up @@ -210,12 +211,6 @@ public void discardContent() {
}

private void finish() {
SendCommentActivity activity = (SendCommentActivity) getActivity();
activity.finishFromFragment();
}

private void finishAfterTransition() {
SendCommentActivity activity = (SendCommentActivity) getActivity();
activity.finishAfterTransitionFromFragment();
FragmentFinishable.finish(getActivity());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2018 Zhang Hai <Dreaming.in.Code.ZH@Gmail.com>
* All Rights Reserved.
*/

package me.zhanghai.android.douya.ui;

import android.app.Activity;

public interface FragmentFinishable {

void finishFromFragment();

void finishAfterTransitionFromFragment();

static void finish(Activity activity) {
((FragmentFinishable) activity).finishFromFragment();
}

static void finishAfterTransition(Activity activity) {
((FragmentFinishable) activity).finishAfterTransitionFromFragment();
}
}

0 comments on commit 4050685

Please sign in to comment.