Create PostMediaService to submit video and image posts.

This commit is contained in:
Alex Ning 2019-08-06 17:35:54 +08:00
parent 5bb9cf7891
commit fe898a5c6c
15 changed files with 410 additions and 166 deletions

Binary file not shown.

View File

@ -10,6 +10,8 @@
android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="22" /> android:maxSdkVersion="22" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<application <application
android:name=".Infinity" android:name=".Infinity"
android:allowBackup="true" android:allowBackup="true"
@ -19,6 +21,11 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"> android:usesCleartextTraffic="true">
<service
android:name=".PostMediaService"
android:enabled="true"
android:exported="false"></service>
<activity <activity
android:name=".FilteredPostsActivity" android:name=".FilteredPostsActivity"
android:parentActivityName=".MainActivity" android:parentActivityName=".MainActivity"
@ -62,17 +69,20 @@
android:name=".PostVideoActivity" android:name=".PostVideoActivity"
android:label="@string/post_video_activity_label" android:label="@string/post_video_activity_label"
android:parentActivityName=".MainActivity" android:parentActivityName=".MainActivity"
android:theme="@style/AppTheme.NoActionBar" /> android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustResize" />
<activity <activity
android:name=".PostImageActivity" android:name=".PostImageActivity"
android:label="@string/post_image_activity_label" android:label="@string/post_image_activity_label"
android:parentActivityName=".MainActivity" android:parentActivityName=".MainActivity"
android:theme="@style/AppTheme.NoActionBar" /> android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustResize" />
<activity <activity
android:name=".PostLinkActivity" android:name=".PostLinkActivity"
android:label="@string/post_link_activity_label" android:label="@string/post_link_activity_label"
android:parentActivityName=".MainActivity" android:parentActivityName=".MainActivity"
android:theme="@style/AppTheme.NoActionBar" /> android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustResize" />
<activity <activity
android:name=".SubscribedThingListingActivity" android:name=".SubscribedThingListingActivity"
android:label="@string/subscriptions" android:label="@string/subscriptions"

View File

@ -41,7 +41,7 @@ public class CustomMarkwonView extends MarkwonView {
builder.setToolbarColor(context.getResources().getColor(R.color.colorPrimary)); builder.setToolbarColor(context.getResources().getColor(R.color.colorPrimary));
CustomTabsIntent customTabsIntent = builder.build(); CustomTabsIntent customTabsIntent = builder.build();
Uri uri = Uri.parse(link); Uri uri = Uri.parse(link);
if(uri.getHost() != null && uri.getHost().equals("www.reddit.com")) { if(uri.getHost() != null && uri.getHost().contains("reddit.com")) {
customTabsIntent.intent.setPackage(context.getPackageName()); customTabsIntent.intent.setPackage(context.getPackageName());
} }
customTabsIntent.launchUrl(context, uri); customTabsIntent.launchUrl(context, uri);

View File

@ -25,4 +25,5 @@ interface AppComponent {
void inject(FlairBottomSheetFragment flairBottomSheetFragment); void inject(FlairBottomSheetFragment flairBottomSheetFragment);
void inject(RulesActivity rulesActivity); void inject(RulesActivity rulesActivity);
void inject(CommentsListingFragment commentsListingFragment); void inject(CommentsListingFragment commentsListingFragment);
void inject(PostMediaService postMediaService);
} }

View File

@ -309,8 +309,8 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
loadUserData(); loadUserData();
return true; return true;
case R.id.action_lazy_mode_main_activity: case R.id.action_lazy_mode_main_activity:
MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_main_activity); /*MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_main_activity);
/*if(isInLazyMode) { if(isInLazyMode) {
isInLazyMode = false; isInLazyMode = false;
((FragmentCommunicator) mFragment).stopLazyMode(); ((FragmentCommunicator) mFragment).stopLazyMode();
lazyModeItem.setTitle(R.string.action_start_lazy_mode); lazyModeItem.setTitle(R.string.action_start_lazy_mode);

View File

@ -0,0 +1,5 @@
package ml.docilealligator.infinityforreddit;
class NotificationUtils {
static final String CHANNEL_POST_MEDIA = "Post Media";
}

View File

@ -2,9 +2,8 @@ package ml.docilealligator.infinityforreddit;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.provider.MediaStore; import android.provider.MediaStore;
@ -15,7 +14,6 @@ import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -28,15 +26,15 @@ import androidx.core.content.FileProvider;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager; import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import com.libRG.CustomTextView; import com.libRG.CustomTextView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Locale;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -46,8 +44,6 @@ import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import pl.droidsonroids.gif.GifImageView; import pl.droidsonroids.gif.GifImageView;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Retrofit; import retrofit2.Retrofit;
public class PostImageActivity extends AppCompatActivity implements FlairBottomSheetFragment.FlairSelectionCallback { public class PostImageActivity extends AppCompatActivity implements FlairBottomSheetFragment.FlairSelectionCallback {
@ -60,6 +56,7 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS
private static final String SUBREDDIT_IS_USER_STATE = "SIUS"; private static final String SUBREDDIT_IS_USER_STATE = "SIUS";
private static final String IMAGE_URI_STATE = "IUS"; private static final String IMAGE_URI_STATE = "IUS";
private static final String LOAD_SUBREDDIT_ICON_STATE = "LSIS"; private static final String LOAD_SUBREDDIT_ICON_STATE = "LSIS";
private static final String IS_POSTING_STATE = "IPS";
private static final String FLAIR_STATE = "FS"; private static final String FLAIR_STATE = "FS";
private static final String IS_SPOILER_STATE = "ISS"; private static final String IS_SPOILER_STATE = "ISS";
private static final String IS_NSFW_STATE = "INS"; private static final String IS_NSFW_STATE = "INS";
@ -88,15 +85,17 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS
private boolean subredditSelected = false; private boolean subredditSelected = false;
private boolean subredditIsUser; private boolean subredditIsUser;
private boolean loadSubredditIconSuccessful = true; private boolean loadSubredditIconSuccessful = true;
private boolean isPosting;
private Uri imageUri; private Uri imageUri;
private String flair = null; private String flair = null;
private boolean isSpoiler = false; private boolean isSpoiler = false;
private boolean isNSFW = false; private boolean isNSFW = false;
private Menu mMemu;
private RequestManager mGlide; private RequestManager mGlide;
private Locale mLocale;
private FlairBottomSheetFragment flairSelectionBottomSheetFragment; private FlairBottomSheetFragment flairSelectionBottomSheetFragment;
private Snackbar mPostingSnackbar;
@Inject @Inject
@Named("no_oauth") @Named("no_oauth")
@ -125,13 +124,14 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS
ButterKnife.bind(this); ButterKnife.bind(this);
EventBus.getDefault().register(this);
((Infinity) getApplication()).getmAppComponent().inject(this); ((Infinity) getApplication()).getmAppComponent().inject(this);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mGlide = Glide.with(this); mGlide = Glide.with(this);
mLocale = getResources().getConfiguration().locale;
if(savedInstanceState != null) { if(savedInstanceState != null) {
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE); subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
@ -139,6 +139,7 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS
subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE); subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
subredditIsUser = savedInstanceState.getBoolean(SUBREDDIT_IS_USER_STATE); subredditIsUser = savedInstanceState.getBoolean(SUBREDDIT_IS_USER_STATE);
loadSubredditIconSuccessful = savedInstanceState.getBoolean(LOAD_SUBREDDIT_ICON_STATE); loadSubredditIconSuccessful = savedInstanceState.getBoolean(LOAD_SUBREDDIT_ICON_STATE);
isPosting = savedInstanceState.getBoolean(IS_POSTING_STATE);
flair = savedInstanceState.getString(FLAIR_STATE); flair = savedInstanceState.getString(FLAIR_STATE);
isSpoiler = savedInstanceState.getBoolean(IS_SPOILER_STATE); isSpoiler = savedInstanceState.getBoolean(IS_SPOILER_STATE);
isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE); isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE);
@ -157,6 +158,11 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS
} }
displaySubredditIcon(); displaySubredditIcon();
if(isPosting) {
mPostingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE);
mPostingSnackbar.show();
}
if(flair != null) { if(flair != null) {
flairTextView.setText(flair); flairTextView.setText(flair);
flairTextView.setBackgroundColor(getResources().getColor(R.color.backgroundColorPrimaryDark)); flairTextView.setBackgroundColor(getResources().getColor(R.color.backgroundColorPrimaryDark));
@ -168,6 +174,8 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS
nsfwTextView.setBackgroundColor(getResources().getColor(R.color.colorAccent)); nsfwTextView.setBackgroundColor(getResources().getColor(R.color.colorAccent));
} }
} else { } else {
isPosting = false;
if(getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) { if(getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME); subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME);
subreditNameTextView.setText(subredditName); subreditNameTextView.setText(subredditName);
@ -302,6 +310,11 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.post_image_activity, menu); getMenuInflater().inflate(R.menu.post_image_activity, menu);
mMemu = menu;
if(isPosting) {
mMemu.findItem(R.id.action_send_post_image_activity).setEnabled(false);
mMemu.findItem(R.id.action_send_post_image_activity).getIcon().setAlpha(130);
}
return true; return true;
} }
@ -322,10 +335,12 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS
return true; return true;
} }
isPosting = true;
item.setEnabled(false); item.setEnabled(false);
item.getIcon().setAlpha(130); item.getIcon().setAlpha(130);
Snackbar postingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE); mPostingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE);
postingSnackbar.show(); mPostingSnackbar.show();
String subredditName; String subredditName;
if(subredditIsUser) { if(subredditIsUser) {
@ -334,76 +349,27 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS
subredditName = subreditNameTextView.getText().toString(); subredditName = subreditNameTextView.getText().toString();
} }
Glide.with(this) Intent intent = new Intent(this, PostMediaService.class);
.asBitmap() intent.setData(imageUri);
.load(imageUri) intent.putExtra(PostMediaService.EXTRA_SUBREDDIT_NAME, subredditName);
.into(new CustomTarget<Bitmap>() { intent.putExtra(PostMediaService.EXTRA_TITLE, titleEditText.getText().toString());
intent.putExtra(PostMediaService.EXTRA_FLAIR, flair);
intent.putExtra(PostMediaService.EXTRA_IS_SPOILER, isSpoiler);
intent.putExtra(PostMediaService.EXTRA_IS_NSFW, isNSFW);
intent.putExtra(PostMediaService.EXTRA_POST_TYPE, PostMediaService.EXTRA_POST_TYPE_IMAGE);
@Override if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) { startForegroundService(intent);
SubmitPost.submitImagePost(mOauthRetrofit, mUploadMediaRetrofit, sharedPreferences, } else {
mLocale, subredditName, titleEditText.getText().toString(), resource, startService(intent);
flair, isSpoiler, isNSFW, new SubmitPost.SubmitPostListener() { }
@Override
public void submitSuccessful(Post post) {
RedditAPI api = mOauthRetrofit.create(RedditAPI.class);
Call<String> getPost = api.getUserBestPosts(mUserInfoSharedPreferences.getString(SharedPreferencesUtils.USER_KEY, ""), null,
RedditUtils.getOAuthHeader(sharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, "")));
getPost.enqueue(new Callback<String>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
if(response.isSuccessful()) {
Toast.makeText(PostImageActivity.this, R.string.image_is_processing, Toast.LENGTH_SHORT).show();
Intent intent = new Intent(PostImageActivity.this, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY,
mUserInfoSharedPreferences.getString(SharedPreferencesUtils.USER_KEY, ""));
startActivity(intent);
finish();
} else {
startViewUserDetailActivity();
}
}
@Override
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
startViewUserDetailActivity();
}
});
}
@Override
public void submitFailed(@Nullable String errorMessage) {
postingSnackbar.dismiss();
item.setEnabled(true);
item.getIcon().setAlpha(255);
if(errorMessage == null) {
Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
} else {
Snackbar.make(coordinatorLayout, errorMessage, Snackbar.LENGTH_SHORT).show();
}
}
});
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
return true; return true;
} }
return false; return false;
} }
private void startViewUserDetailActivity() {
Intent intent = new Intent(PostImageActivity.this, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY,
mUserInfoSharedPreferences.getString(SharedPreferencesUtils.USER_KEY, ""));
startActivity(intent);
finish();
}
@Override @Override
protected void onSaveInstanceState(@NonNull Bundle outState) { protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
@ -415,6 +381,7 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS
outState.putString(IMAGE_URI_STATE, imageUri.toString()); outState.putString(IMAGE_URI_STATE, imageUri.toString());
} }
outState.putBoolean(LOAD_SUBREDDIT_ICON_STATE, loadSubredditIconSuccessful); outState.putBoolean(LOAD_SUBREDDIT_ICON_STATE, loadSubredditIconSuccessful);
outState.putBoolean(IS_POSTING_STATE, isPosting);
outState.putString(FLAIR_STATE, flair); outState.putString(FLAIR_STATE, flair);
outState.putBoolean(IS_SPOILER_STATE, isSpoiler); outState.putBoolean(IS_SPOILER_STATE, isSpoiler);
outState.putBoolean(IS_NSFW_STATE, isNSFW); outState.putBoolean(IS_NSFW_STATE, isNSFW);
@ -456,6 +423,12 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS
} }
} }
@Override
protected void onDestroy() {
EventBus.getDefault().unregister(this);
super.onDestroy();
}
@Override @Override
public void flairSelected(String flair) { public void flairSelected(String flair) {
this.flair = flair; this.flair = flair;
@ -463,4 +436,25 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS
flairTextView.setBackgroundColor(getResources().getColor(R.color.backgroundColorPrimaryDark)); flairTextView.setBackgroundColor(getResources().getColor(R.color.backgroundColorPrimaryDark));
flairSelectionBottomSheetFragment.dismiss(); flairSelectionBottomSheetFragment.dismiss();
} }
@Subscribe
public void onSubmitImagePostEvent(SubmitImagePostEvent submitImagePostEvent) {
isPosting = false;
if(submitImagePostEvent.postSuccess) {
Intent intent = new Intent(this, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY,
mUserInfoSharedPreferences.getString(SharedPreferencesUtils.USER_KEY, ""));
startActivity(intent);
finish();
} else {
mPostingSnackbar.dismiss();
mMemu.getItem(R.id.action_send_post_image_activity).setEnabled(true);
mMemu.getItem(R.id.action_send_post_image_activity).getIcon().setAlpha(255);
if (submitImagePostEvent.errorMessage == null || submitImagePostEvent.errorMessage.equals("")) {
Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
} else {
Snackbar.make(coordinatorLayout, submitImagePostEvent.errorMessage, Snackbar.LENGTH_SHORT).show();
}
}
}
} }

View File

@ -0,0 +1,203 @@
package ml.docilealligator.infinityforreddit;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import org.greenrobot.eventbus.EventBus;
import java.io.FileInputStream;
import java.io.IOException;
import javax.inject.Inject;
import javax.inject.Named;
import retrofit2.Retrofit;
public class PostMediaService extends Service {
static final String EXTRA_SUBREDDIT_NAME = "ESN";
static final String EXTRA_TITLE = "ET";
static final String EXTRA_FLAIR = "EF";
static final String EXTRA_IS_SPOILER = "EIS";
static final String EXTRA_IS_NSFW = "EIN";
static final String EXTRA_POST_TYPE = "EPT";
static final int EXTRA_POST_TYPE_IMAGE = 0;
static final int EXTRA_POST_TYPE_VIDEO = 1;
@Inject
@Named("oauth")
Retrofit mOauthRetrofit;
@Inject
@Named("upload_media")
Retrofit mUploadMediaRetrofit;
@Inject
@Named("upload_video")
Retrofit mUploadVideoRetrofit;
@Inject
@Named("user_info")
SharedPreferences mUserInfoSharedPreferences;
@Inject
@Named("auth_info")
SharedPreferences sharedPreferences;
public PostMediaService() {
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
((Infinity) getApplication()).getmAppComponent().inject(this);
Uri mediaUri = intent.getData();
String subredditName = intent.getExtras().getString(EXTRA_SUBREDDIT_NAME);
String title = intent.getExtras().getString(EXTRA_TITLE);
String flair = intent.getExtras().getString(EXTRA_FLAIR);
boolean isSpoiler = intent.getExtras().getBoolean(EXTRA_IS_SPOILER);
boolean isNSFW = intent.getExtras().getBoolean(EXTRA_IS_NSFW);
int postType = intent.getExtras().getInt(EXTRA_POST_TYPE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel serviceChannel = new NotificationChannel(
NotificationUtils.CHANNEL_POST_MEDIA,
NotificationUtils.CHANNEL_POST_MEDIA,
NotificationManager.IMPORTANCE_LOW
);
NotificationManager manager = getSystemService(NotificationManager.class);
manager.createNotificationChannel(serviceChannel);
}
if(postType == EXTRA_POST_TYPE_IMAGE) {
startForeground(1, createNotification(R.string.posting_image));
submitImagePost(mediaUri, subredditName, title, flair, isSpoiler, isNSFW);
} else {
startForeground(1, createNotification(R.string.posting_video));
submitVideoPost(mediaUri, subredditName, title, flair, isSpoiler, isNSFW);
}
return START_NOT_STICKY;
}
private Notification createNotification(int stringResId) {
return new NotificationCompat.Builder(this, NotificationUtils.CHANNEL_POST_MEDIA)
.setContentTitle(getString(stringResId))
.setContentText(getString(R.string.please_wait))
.setSmallIcon(R.mipmap.ic_launcher_round)
.build();
}
private void submitImagePost(Uri imageUri, String subredditName, String title, String flair,
boolean isSpoiler, boolean isNSFW) {
Glide.with(this)
.asBitmap()
.load(imageUri)
.into(new CustomTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
SubmitPost.submitImagePost(mOauthRetrofit, mUploadMediaRetrofit, sharedPreferences,
getResources().getConfiguration().locale, subredditName, title, resource,
flair, isSpoiler, isNSFW, new SubmitPost.SubmitPostListener() {
@Override
public void submitSuccessful(Post post) {
EventBus.getDefault().post(new SubmitImagePostEvent(true, null));
Toast.makeText(PostMediaService.this, R.string.image_is_processing, Toast.LENGTH_SHORT).show();
stopForeground(true);
stopSelf();
}
@Override
public void submitFailed(@Nullable String errorMessage) {
EventBus.getDefault().post(new SubmitImagePostEvent(false, errorMessage));
stopForeground(true);
stopSelf();
}
});
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
}
private void submitVideoPost(Uri videoUri, String subredditName, String title, String flair,
boolean isSpoiler, boolean isNSFW) {
try (ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(videoUri, "r")) {
FileInputStream in = new FileInputStream(pfd.getFileDescriptor());
byte[] buffer;
buffer = new byte[in.available()];
while (in.read(buffer) != -1);
Glide.with(this)
.asBitmap()
.load(videoUri)
.into(new CustomTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
SubmitPost.submitVideoPost(mOauthRetrofit, mUploadMediaRetrofit, mUploadVideoRetrofit,
sharedPreferences, getResources().getConfiguration().locale, subredditName, title,
buffer, getContentResolver().getType(videoUri), resource, flair, isSpoiler, isNSFW,
new SubmitPost.SubmitPostListener() {
@Override
public void submitSuccessful(Post post) {
EventBus.getDefault().post(new SubmitVideoPostEvent(true, false, null));
Toast.makeText(PostMediaService.this, R.string.video_is_processing, Toast.LENGTH_SHORT).show();
stopForeground(true);
stopSelf();
}
@Override
public void submitFailed(@Nullable String errorMessage) {
EventBus.getDefault().post(new SubmitVideoPostEvent(false, false, errorMessage));
stopForeground(true);
stopSelf();
}
});
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
} catch (IOException e) {
e.printStackTrace();
EventBus.getDefault().post(new SubmitVideoPostEvent(false, true, null));
stopForeground(true);
stopSelf();
}
}
}

View File

@ -2,11 +2,9 @@ package ml.docilealligator.infinityforreddit;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -14,7 +12,6 @@ import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView; import android.widget.VideoView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -27,15 +24,12 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager; import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import com.libRG.CustomTextView; import com.libRG.CustomTextView;
import java.io.FileInputStream; import org.greenrobot.eventbus.EventBus;
import java.io.IOException; import org.greenrobot.eventbus.Subscribe;
import java.util.Locale;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -57,6 +51,7 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
private static final String SUBREDDIT_IS_USER_STATE = "SIUS"; private static final String SUBREDDIT_IS_USER_STATE = "SIUS";
private static final String VIDEO_URI_STATE = "IUS"; private static final String VIDEO_URI_STATE = "IUS";
private static final String LOAD_SUBREDDIT_ICON_STATE = "LSIS"; private static final String LOAD_SUBREDDIT_ICON_STATE = "LSIS";
private static final String IS_POSTING_STATE = "IPS";
private static final String FLAIR_STATE = "FS"; private static final String FLAIR_STATE = "FS";
private static final String IS_SPOILER_STATE = "ISS"; private static final String IS_SPOILER_STATE = "ISS";
private static final String IS_NSFW_STATE = "INS"; private static final String IS_NSFW_STATE = "INS";
@ -86,14 +81,16 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
private boolean subredditIsUser; private boolean subredditIsUser;
private Uri videoUri; private Uri videoUri;
private boolean loadSubredditIconSuccessful = true; private boolean loadSubredditIconSuccessful = true;
private boolean isPosting;
private String flair = null; private String flair = null;
private boolean isSpoiler = false; private boolean isSpoiler = false;
private boolean isNSFW = false; private boolean isNSFW = false;
private Menu mMemu;
private RequestManager mGlide; private RequestManager mGlide;
private Locale mLocale; private FlairBottomSheetFragment mFlairSelectionBottomSheetFragment;
private FlairBottomSheetFragment flairSelectionBottomSheetFragment; private Snackbar mPostingSnackbar;
@Inject @Inject
@Named("no_oauth") @Named("no_oauth")
@ -126,13 +123,14 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
ButterKnife.bind(this); ButterKnife.bind(this);
EventBus.getDefault().register(this);
((Infinity) getApplication()).getmAppComponent().inject(this); ((Infinity) getApplication()).getmAppComponent().inject(this);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mGlide = Glide.with(this); mGlide = Glide.with(this);
mLocale = getResources().getConfiguration().locale;
if(savedInstanceState != null) { if(savedInstanceState != null) {
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE); subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
@ -140,13 +138,14 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE); subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
subredditIsUser = savedInstanceState.getBoolean(SUBREDDIT_IS_USER_STATE); subredditIsUser = savedInstanceState.getBoolean(SUBREDDIT_IS_USER_STATE);
loadSubredditIconSuccessful = savedInstanceState.getBoolean(LOAD_SUBREDDIT_ICON_STATE); loadSubredditIconSuccessful = savedInstanceState.getBoolean(LOAD_SUBREDDIT_ICON_STATE);
isPosting = savedInstanceState.getBoolean(IS_POSTING_STATE);
flair = savedInstanceState.getString(FLAIR_STATE); flair = savedInstanceState.getString(FLAIR_STATE);
isSpoiler = savedInstanceState.getBoolean(IS_SPOILER_STATE); isSpoiler = savedInstanceState.getBoolean(IS_SPOILER_STATE);
isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE); isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE);
if(savedInstanceState.getString(VIDEO_URI_STATE) != null) { if(savedInstanceState.getString(VIDEO_URI_STATE) != null) {
videoUri = Uri.parse(savedInstanceState.getString(VIDEO_URI_STATE)); videoUri = Uri.parse(savedInstanceState.getString(VIDEO_URI_STATE));
loadImage(); loadVideo();
} }
if(subredditName != null) { if(subredditName != null) {
@ -158,6 +157,11 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
} }
displaySubredditIcon(); displaySubredditIcon();
if(isPosting) {
mPostingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE);
mPostingSnackbar.show();
}
if(flair != null) { if(flair != null) {
flairTextView.setText(flair); flairTextView.setText(flair);
flairTextView.setBackgroundColor(getResources().getColor(R.color.backgroundColorPrimaryDark)); flairTextView.setBackgroundColor(getResources().getColor(R.color.backgroundColorPrimaryDark));
@ -169,6 +173,8 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
nsfwTextView.setBackgroundColor(getResources().getColor(R.color.colorAccent)); nsfwTextView.setBackgroundColor(getResources().getColor(R.color.colorAccent));
} }
} else { } else {
isPosting = false;
if(getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) { if(getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME); subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME);
subreditNameTextView.setText(subredditName); subreditNameTextView.setText(subredditName);
@ -206,11 +212,11 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
flairTextView.setOnClickListener(view -> { flairTextView.setOnClickListener(view -> {
if(flair == null) { if(flair == null) {
flairSelectionBottomSheetFragment = new FlairBottomSheetFragment(); mFlairSelectionBottomSheetFragment = new FlairBottomSheetFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(FlairBottomSheetFragment.EXTRA_SUBREDDIT_NAME, subredditName); bundle.putString(FlairBottomSheetFragment.EXTRA_SUBREDDIT_NAME, subredditName);
flairSelectionBottomSheetFragment.setArguments(bundle); mFlairSelectionBottomSheetFragment.setArguments(bundle);
flairSelectionBottomSheetFragment.show(getSupportFragmentManager(), flairSelectionBottomSheetFragment.getTag()); mFlairSelectionBottomSheetFragment.show(getSupportFragmentManager(), mFlairSelectionBottomSheetFragment.getTag());
} else { } else {
flairTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); flairTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent));
flairTextView.setText(getString(R.string.flair)); flairTextView.setText(getString(R.string.flair));
@ -266,7 +272,7 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
}); });
} }
private void loadImage() { private void loadVideo() {
constraintLayout.setVisibility(View.GONE); constraintLayout.setVisibility(View.GONE);
videoView.setVisibility(View.VISIBLE); videoView.setVisibility(View.VISIBLE);
selectAgainTextView.setVisibility(View.VISIBLE); selectAgainTextView.setVisibility(View.VISIBLE);
@ -299,7 +305,12 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.post_image_activity, menu); getMenuInflater().inflate(R.menu.post_video_activity, menu);
mMemu = menu;
if(isPosting) {
mMemu.findItem(R.id.action_send_post_video_activity).setEnabled(false);
mMemu.findItem(R.id.action_send_post_video_activity).getIcon().setAlpha(130);
}
return true; return true;
} }
@ -309,7 +320,7 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
case android.R.id.home: case android.R.id.home:
finish(); finish();
return true; return true;
case R.id.action_send_post_image_activity: case R.id.action_send_post_video_activity:
if(!subredditSelected) { if(!subredditSelected) {
Snackbar.make(coordinatorLayout, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show(); Snackbar.make(coordinatorLayout, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
return true; return true;
@ -320,10 +331,12 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
return true; return true;
} }
isPosting = true;
item.setEnabled(false); item.setEnabled(false);
item.getIcon().setAlpha(130); item.getIcon().setAlpha(130);
Snackbar postingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE); mPostingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE);
postingSnackbar.show(); mPostingSnackbar.show();
String subredditName; String subredditName;
if(subredditIsUser) { if(subredditIsUser) {
@ -332,55 +345,21 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
subredditName = subreditNameTextView.getText().toString(); subredditName = subreditNameTextView.getText().toString();
} }
try (ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(videoUri, "r")) { Intent intent = new Intent(this, PostMediaService.class);
FileInputStream in = new FileInputStream(pfd.getFileDescriptor()); intent.setData(videoUri);
byte[] buffer; intent.putExtra(PostMediaService.EXTRA_SUBREDDIT_NAME, subredditName);
buffer = new byte[in.available()]; intent.putExtra(PostMediaService.EXTRA_TITLE, titleEditText.getText().toString());
while (in.read(buffer) != -1); intent.putExtra(PostMediaService.EXTRA_FLAIR, flair);
intent.putExtra(PostMediaService.EXTRA_IS_SPOILER, isSpoiler);
intent.putExtra(PostMediaService.EXTRA_IS_NSFW, isNSFW);
intent.putExtra(PostMediaService.EXTRA_POST_TYPE, PostMediaService.EXTRA_POST_TYPE_VIDEO);
Glide.with(this) if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
.asBitmap() startForegroundService(intent);
.load(videoUri) } else {
.into(new CustomTarget<Bitmap>() { startService(intent);
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
SubmitPost.submitVideoPost(mOauthRetrofit, mUploadMediaRetrofit, mUploadVideoRetrofit,
sharedPreferences, mLocale, subredditName, titleEditText.getText().toString(),
buffer, getContentResolver().getType(videoUri), resource, flair, isSpoiler, isNSFW,
new SubmitPost.SubmitPostListener() {
@Override
public void submitSuccessful(Post post) {
Toast.makeText(PostVideoActivity.this, R.string.video_is_processing, Toast.LENGTH_SHORT).show();
Intent intent = new Intent(PostVideoActivity.this, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY,
mUserInfoSharedPreferences.getString(SharedPreferencesUtils.USER_KEY, ""));
startActivity(intent);
finish();
}
@Override
public void submitFailed(@Nullable String errorMessage) {
postingSnackbar.dismiss();
item.setEnabled(true);
item.getIcon().setAlpha(255);
if (errorMessage == null || errorMessage.equals("")) {
Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
} else {
Snackbar.make(coordinatorLayout, errorMessage, Snackbar.LENGTH_SHORT).show();
}
}
});
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
} catch (IOException e) {
e.printStackTrace();
Snackbar.make(coordinatorLayout, R.string.error_processing_video, Snackbar.LENGTH_SHORT).show();
} }
return true; return true;
} }
@ -404,6 +383,7 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
outState.putString(VIDEO_URI_STATE, videoUri.toString()); outState.putString(VIDEO_URI_STATE, videoUri.toString());
} }
outState.putBoolean(LOAD_SUBREDDIT_ICON_STATE, loadSubredditIconSuccessful); outState.putBoolean(LOAD_SUBREDDIT_ICON_STATE, loadSubredditIconSuccessful);
outState.putBoolean(IS_POSTING_STATE, isPosting);
outState.putString(FLAIR_STATE, flair); outState.putString(FLAIR_STATE, flair);
outState.putBoolean(IS_SPOILER_STATE, isSpoiler); outState.putBoolean(IS_SPOILER_STATE, isSpoiler);
outState.putBoolean(IS_NSFW_STATE, isNSFW); outState.putBoolean(IS_NSFW_STATE, isNSFW);
@ -436,19 +416,48 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS
} }
videoUri = data.getData(); videoUri = data.getData();
loadImage(); loadVideo();
} }
} else if (requestCode == CAPTURE_VIDEO_REQUEST_CODE) { } else if (requestCode == CAPTURE_VIDEO_REQUEST_CODE) {
videoUri = data.getData(); videoUri = data.getData();
loadImage(); loadVideo();
} }
} }
@Override
protected void onDestroy() {
EventBus.getDefault().unregister(this);
super.onDestroy();
}
@Override @Override
public void flairSelected(String flair) { public void flairSelected(String flair) {
this.flair = flair; this.flair = flair;
flairTextView.setText(flair); flairTextView.setText(flair);
flairTextView.setBackgroundColor(getResources().getColor(R.color.backgroundColorPrimaryDark)); flairTextView.setBackgroundColor(getResources().getColor(R.color.backgroundColorPrimaryDark));
flairSelectionBottomSheetFragment.dismiss(); mFlairSelectionBottomSheetFragment.dismiss();
}
@Subscribe
public void onSubmitVideoPostEvent(SubmitVideoPostEvent submitVideoPostEvent) {
isPosting = false;
if(submitVideoPostEvent.postSuccess) {
Intent intent = new Intent(this, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY,
mUserInfoSharedPreferences.getString(SharedPreferencesUtils.USER_KEY, ""));
startActivity(intent);
finish();
} else if(submitVideoPostEvent.errorProcessingVideo) {
Snackbar.make(coordinatorLayout, R.string.error_processing_video, Snackbar.LENGTH_SHORT).show();
} else {
mPostingSnackbar.dismiss();
mMemu.getItem(R.id.action_send_post_video_activity).setEnabled(true);
mMemu.getItem(R.id.action_send_post_video_activity).getIcon().setAlpha(255);
if (submitVideoPostEvent.errorMessage == null || submitVideoPostEvent.errorMessage.equals("")) {
Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
} else {
Snackbar.make(coordinatorLayout, submitVideoPostEvent.errorMessage, Snackbar.LENGTH_SHORT).show();
}
}
} }
} }

View File

@ -0,0 +1,11 @@
package ml.docilealligator.infinityforreddit;
public class SubmitImagePostEvent {
public boolean postSuccess;
public String errorMessage;
public SubmitImagePostEvent(boolean postSuccess, String errorMessage) {
this.postSuccess = postSuccess;
this.errorMessage = errorMessage;
}
}

View File

@ -83,7 +83,6 @@ class SubmitPost {
uploadImageParams.put(RedditUtils.FILEPATH_KEY, "post_video." + fileType); uploadImageParams.put(RedditUtils.FILEPATH_KEY, "post_video." + fileType);
uploadImageParams.put(RedditUtils.MIMETYPE_KEY, mimeType); uploadImageParams.put(RedditUtils.MIMETYPE_KEY, mimeType);
Log.i("map", RedditUtils.getOAuthHeader(accessToken).toString());
Call<String> uploadImageCall = api.uploadImage(RedditUtils.getOAuthHeader(accessToken), uploadImageParams); Call<String> uploadImageCall = api.uploadImage(RedditUtils.getOAuthHeader(accessToken), uploadImageParams);
uploadImageCall.enqueue(new Callback<String>() { uploadImageCall.enqueue(new Callback<String>() {
@Override @Override

View File

@ -0,0 +1,13 @@
package ml.docilealligator.infinityforreddit;
public class SubmitVideoPostEvent {
public boolean postSuccess;
public boolean errorProcessingVideo;
public String errorMessage;
public SubmitVideoPostEvent(boolean postSuccess, boolean errorProcessingVideo, String errorMessage) {
this.postSuccess = postSuccess;
this.errorProcessingVideo = errorProcessingVideo;
this.errorMessage = errorMessage;
}
}

View File

@ -63,7 +63,6 @@ public class ViewUserDetailActivity extends AppCompatActivity {
private SectionsPagerAdapter sectionsPagerAdapter; private SectionsPagerAdapter sectionsPagerAdapter;
private Fragment mFragment;
private SubscribedUserDao subscribedUserDao; private SubscribedUserDao subscribedUserDao;
private RequestManager glide; private RequestManager glide;
private UserViewModel userViewModel; private UserViewModel userViewModel;
@ -330,15 +329,12 @@ public class ViewUserDetailActivity extends AppCompatActivity {
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_IS_USER, true); intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_IS_USER, true);
intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_SUBREDDITS, false); intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_SUBREDDITS, false);
startActivity(intent); startActivity(intent);
break; return true;
case R.id.action_refresh_view_user_detail_activity: case R.id.action_refresh_view_user_detail_activity:
if (mFragment instanceof FragmentCommunicator) { sectionsPagerAdapter.refresh();
((FragmentCommunicator) mFragment).refresh(); return true;
return true;
}
break;
case R.id.action_lazy_mode_view_user_detail_activity: case R.id.action_lazy_mode_view_user_detail_activity:
MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_view_user_detail_activity); /*MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_view_user_detail_activity);
if(isInLazyMode) { if(isInLazyMode) {
isInLazyMode = false; isInLazyMode = false;
((FragmentCommunicator) mFragment).stopLazyMode(); ((FragmentCommunicator) mFragment).stopLazyMode();
@ -354,7 +350,7 @@ public class ViewUserDetailActivity extends AppCompatActivity {
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED); params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED);
collapsingToolbarLayout.setLayoutParams(params); collapsingToolbarLayout.setLayoutParams(params);
} }
return true; return true;*/
} }
return false; return false;
} }
@ -484,11 +480,10 @@ public class ViewUserDetailActivity extends AppCompatActivity {
} }
public void refresh() { public void refresh() {
if(postFragment != null) { if(viewPager.getCurrentItem() == 0) {
((FragmentCommunicator) postFragment).refresh(); postFragment.refresh();
} } else {
if(commentsListingFragment != null) { commentsListingFragment.refresh();
((FragmentCommunicator) commentsListingFragment).refresh();
} }
} }
} }

View File

@ -160,4 +160,8 @@
<string name="gif">GIF</string> <string name="gif">GIF</string>
<string name="best">Best</string> <string name="best">Best</string>
<string name="search">Search</string> <string name="search">Search</string>
<string name="posting_video">Posting video</string>
<string name="posting_image">Posting image</string>
<string name="please_wait">Please wait.</string>
</resources> </resources>