Preparing to submit image posts.

This commit is contained in:
Alex Ning 2019-07-13 00:05:38 +08:00
parent 8c55fbbde9
commit de4b53ddf0
12 changed files with 457 additions and 5 deletions

View File

@ -35,9 +35,9 @@
<map> <map>
<entry key="assetSourceType" value="FILE" /> <entry key="assetSourceType" value="FILE" />
<entry key="color" value="ffffff" /> <entry key="color" value="ffffff" />
<entry key="outputName" value="ic_outline_check_circle_outline_24px" /> <entry key="outputName" value="ic_outline_add_photo_24px" />
<entry key="overrideSize" value="true" /> <entry key="overrideSize" value="true" />
<entry key="sourceFile" value="$USER_HOME$/Downloads/outline-check_circle_outline-24px.svg" /> <entry key="sourceFile" value="$USER_HOME$/Downloads/outline-add_photo_alternate-24px.svg" />
</map> </map>
</option> </option>
</PersistentState> </PersistentState>

Binary file not shown.

View File

@ -19,6 +19,11 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"> android:usesCleartextTraffic="true">
<activity
android:name=".PostImageActivity"
android:label="@string/post_image_activity_label"
android:parentActivityName=".MainActivity"
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"

View File

@ -20,4 +20,5 @@ interface AppComponent {
void inject(PostTextActivity postTextActivity); void inject(PostTextActivity postTextActivity);
void inject(SubscribedSubredditsListingFragment subscribedSubredditsListingFragment); void inject(SubscribedSubredditsListingFragment subscribedSubredditsListingFragment);
void inject(PostLinkActivity postLinkActivity); void inject(PostLinkActivity postLinkActivity);
void inject(PostImageActivity postImageActivity);
} }

View File

@ -248,7 +248,8 @@ public class MainActivity extends AppCompatActivity {
dialog.dismiss(); dialog.dismiss();
}); });
imageTypeLinearLayout.setOnClickListener(view -> { imageTypeLinearLayout.setOnClickListener(view -> {
Toast.makeText(this, "Not implemented yet", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(MainActivity.this, PostImageActivity.class);
startActivity(intent);
dialog.dismiss(); dialog.dismiss();
}); });
videoTypeLinearLayout.setOnClickListener(view -> { videoTypeLinearLayout.setOnClickListener(view -> {

View File

@ -0,0 +1,277 @@
package ml.docilealligator.infinityforreddit;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import java.util.Locale;
import javax.inject.Inject;
import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
public class PostImageActivity extends AppCompatActivity {
static final String EXTRA_SUBREDDIT_NAME = "ESN";
static final String EXTRA_SUBREDDIT_ICON = "ESI";
private static final String SUBREDDIT_NAME_STATE = "SNS";
private static final String SUBREDDIT_ICON_STATE = "SIS";
private static final String SUBREDDIT_SELECTED_STATE = "SSS";
private static final String SUBREDDIT_IS_USER_STATE = "SIUS";
private static final String IMAGE_URI_STATE = "IUS";
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
private static final int PICK_IMAGE_REQUEST_CODE = 1;
@BindView(R.id.coordinator_layout_post_image_activity) CoordinatorLayout coordinatorLayout;
@BindView(R.id.subreddit_icon_gif_image_view_post_image_activity) GifImageView iconGifImageView;
@BindView(R.id.subreddit_name_text_view_post_image_activity) TextView subreditNameTextView;
@BindView(R.id.rules_button_post_image_activity) Button rulesButton;
@BindView(R.id.post_title_edit_text_post_image_activity) EditText titleEditText;
@BindView(R.id.select_image_constraint_layout_post_image_activity) ConstraintLayout constraintLayout;
@BindView(R.id.capture_fab_post_image_activity) FloatingActionButton captureFab;
@BindView(R.id.select_from_library_fab_post_image_activity) FloatingActionButton selectFromLibraryFab;
@BindView(R.id.select_again_text_view_post_image_activity) TextView selectAgainTextView;
@BindView(R.id.image_view_post_image_activity) ImageView imageView;
private String iconUrl;
private String subredditName;
private boolean subredditSelected = false;
private boolean subredditIsUser;
private Uri imageUri;
private RequestManager mGlide;
private Locale mLocale;
@Inject
@Named("oauth")
Retrofit mOauthRetrofit;
@Inject
@Named("auth_info")
SharedPreferences sharedPreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_post_image);
ButterKnife.bind(this);
((Infinity) getApplication()).getmAppComponent().inject(this);
ActionBar actionBar = getSupportActionBar();
Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp);
actionBar.setHomeAsUpIndicator(upArrow);
mGlide = Glide.with(this);
mLocale = getResources().getConfiguration().locale;
if(savedInstanceState != null) {
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
subredditIsUser = savedInstanceState.getBoolean(SUBREDDIT_IS_USER_STATE);
if(savedInstanceState.getString(IMAGE_URI_STATE) != null) {
imageUri = Uri.parse(savedInstanceState.getString(IMAGE_URI_STATE));
loadImage();
}
if(subredditName != null) {
subreditNameTextView.setText(subredditName);
}
if(iconUrl != null && !iconUrl.equals("")) {
mGlide.load(iconUrl)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.error(mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
.into(iconGifImageView);
} else {
mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.into(iconGifImageView);
}
} else {
if(getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME);
iconUrl = getIntent().getExtras().getString(EXTRA_SUBREDDIT_ICON);
subreditNameTextView.setText(subredditName);
} else {
mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.into(iconGifImageView);
}
}
iconGifImageView.setOnClickListener(view -> {
Intent intent = new Intent(this, SubredditSelectionActivity.class);
startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE);
});
subreditNameTextView.setOnClickListener(view -> {
Intent intent = new Intent(this, SubredditSelectionActivity.class);
startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE);
});
captureFab.setOnClickListener(view -> {
});
selectFromLibraryFab.setOnClickListener(view -> {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,getResources().getString(R.string.select_from_gallery)), PICK_IMAGE_REQUEST_CODE);
});
selectAgainTextView.setOnClickListener(view -> {
selectAgainTextView.setVisibility(View.GONE);
mGlide.clear(imageView);
constraintLayout.setVisibility(View.VISIBLE);
});
}
private void loadImage() {
constraintLayout.setVisibility(View.GONE);
imageView.setVisibility(View.VISIBLE);
selectAgainTextView.setVisibility(View.VISIBLE);
mGlide.load(imageUri).into(imageView);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.post_image_activity, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
case R.id.action_send_post_image_activity:
if(!subredditSelected) {
Snackbar.make(coordinatorLayout, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
return true;
}
item.setEnabled(false);
item.getIcon().setAlpha(130);
Snackbar postingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE);
postingSnackbar.show();
String subredditName;
if(subredditIsUser) {
subredditName = "u_" + subreditNameTextView.getText().toString();
} else {
subredditName = subreditNameTextView.getText().toString();
}
/*SubmitPost.submitTextOrLinkPost(mOauthRetrofit, sharedPreferences, mLocale, subredditName,
titleEditText.getText().toString(), contentEditText.getText().toString(),
false, RedditUtils.KIND_LINK, new SubmitPost.SubmitPostListener() {
@Override
public void submitSuccessful(Post post) {
Intent intent = new Intent(PostLinkActivity.this, ViewPostDetailActivity.class);
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_DATA, post);
startActivity(intent);
finish();
}
@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();
}
}
});*/
return true;
}
return false;
}
@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(SUBREDDIT_NAME_STATE, subredditName);
outState.putString(SUBREDDIT_ICON_STATE, iconUrl);
outState.putBoolean(SUBREDDIT_SELECTED_STATE, subredditSelected);
outState.putBoolean(SUBREDDIT_IS_USER_STATE, subredditIsUser);
if(imageUri != null) {
outState.putString(IMAGE_URI_STATE, imageUri.toString());
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
if(resultCode == RESULT_OK) {
subredditName = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME_KEY);
iconUrl = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL_KEY);
subredditSelected = true;
subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER_KEY);
subreditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor));
subreditNameTextView.setText(subredditName);
if(!iconUrl.equals("")) {
mGlide.load(iconUrl)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.error(mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
.into(iconGifImageView);
} else {
mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.into(iconGifImageView);
}
}
} else if(requestCode == PICK_IMAGE_REQUEST_CODE) {
if(resultCode == RESULT_OK) {
if(data == null) {
Snackbar.make(coordinatorLayout, R.string.error_getting_image, Snackbar.LENGTH_SHORT).show();
return;
}
imageUri = data.getData();
loadImage();
}
}
}
}

View File

@ -44,7 +44,7 @@ import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException; import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.SimpleTarget; import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.target.Target; import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition; import com.bumptech.glide.request.transition.Transition;
import com.github.pwittchen.swipe.library.rx2.SimpleSwipeListener; import com.github.pwittchen.swipe.library.rx2.SimpleSwipeListener;
@ -405,7 +405,7 @@ public class ViewImageActivity extends AppCompatActivity {
Glide.with(this) Glide.with(this)
.asBitmap() .asBitmap()
.load(mImageUrl) .load(mImageUrl)
.into(new SimpleTarget<Bitmap>() { .into(new CustomTarget<Bitmap>() {
@SuppressLint("StaticFieldLeak") @SuppressLint("StaticFieldLeak")
@Override @Override
public void onResourceReady(@NonNull final Bitmap resource, @Nullable Transition<? super Bitmap> transition) { public void onResourceReady(@NonNull final Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
@ -499,6 +499,11 @@ public class ViewImageActivity extends AppCompatActivity {
} }
}.execute(); }.execute();
} }
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
}); });
} }

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M21,6h-3.17L16,4h-6v2h5.12l1.83,2L21,8v12L5,20v-9L3,11v9c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L23,8c0,-1.1 -0.9,-2 -2,-2zM8,14c0,2.76 2.24,5 5,5s5,-2.24 5,-5 -2.24,-5 -5,-5 -5,2.24 -5,5zM13,11c1.65,0 3,1.35 3,3s-1.35,3 -3,3 -3,-1.35 -3,-3 1.35,-3 3,-3zM5,6h3L8,4L5,4L5,1L3,1v3L0,4v2h3v3h2z"/>
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M18,20L4,20L4,6h9L13,4L4,4c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2v-9h-2v9zM10.21,16.83l-1.96,-2.36L5.5,18h11l-3.54,-4.71zM20,4L20,1h-2v3h-3c0.01,0.01 0,2 0,2h3v2.99c0.01,0.01 2,0 2,0L20,6h3L23,4h-3z"/>
</vector>

View File

@ -0,0 +1,130 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/coordinator_layout_post_image_activity"
tools:context=".PostImageActivity">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingStart="16dp"
android:paddingEnd="16dp">
<pl.droidsonroids.gif.GifImageView
android:id="@+id/subreddit_icon_gif_image_view_post_image_activity"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentStart="true"
android:layout_centerVertical="true" />
<TextView
android:id="@+id/subreddit_name_text_view_post_image_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toStartOf="@id/rules_button_post_image_activity"
android:layout_toEndOf="@id/subreddit_icon_gif_image_view_post_image_activity"
android:layout_centerVertical="true"
android:layout_marginStart="32dp"
android:layout_marginEnd="16dp"
android:text="@string/choose_a_subreddit" />
<Button
android:id="@+id/rules_button_post_image_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:text="@string/rules"
android:textColor="@color/colorAccent" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/dividerColor" />
<EditText
android:id="@+id/post_title_edit_text_post_image_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:padding="16dp"
android:hint="@string/post_title_hint"
android:inputType="textCapSentences|textMultiLine"
android:textSize="18sp"
android:background="#00000000"
android:textColor="@color/primaryTextColor" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/dividerColor" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/select_image_constraint_layout_post_image_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="32dp">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/capture_fab_post_image_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_outline_add_a_photo_24px"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/select_from_library_fab_post_image_activity"
app:layout_constraintHorizontal_chainStyle="spread" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/select_from_library_fab_post_image_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_outline_select_photo_24px"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/capture_fab_post_image_activity"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_chainStyle="spread" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/select_again_text_view_post_image_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:text="@string/select_again"
android:textColor="@color/colorAccent"
android:visibility="gone" />
<ImageView
android:id="@+id/image_view_post_image_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitStart"
android:adjustViewBounds="true"
android:visibility="gone" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_send_post_image_activity"
android:orderInCategory="1"
android:title="@string/action_send"
android:icon="@drawable/ic_send_white_24dp"
app:showAsAction="ifRoom" />
</menu>

View File

@ -7,6 +7,7 @@
<string name="post_text_activity_label">Text Post</string> <string name="post_text_activity_label">Text Post</string>
<string name="subreddit_selection_activity_label">Select a Subreddit</string> <string name="subreddit_selection_activity_label">Select a Subreddit</string>
<string name="post_link_activity_label">Link Post</string> <string name="post_link_activity_label">Link Post</string>
<string name="post_image_activity_label">Image Post</string>
<string name="navigation_drawer_open">Open navigation drawer</string> <string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string> <string name="navigation_drawer_close">Close navigation drawer</string>
@ -108,4 +109,8 @@
<string name="dialog_post_link">Link</string> <string name="dialog_post_link">Link</string>
<string name="dialog_post_image">Image</string> <string name="dialog_post_image">Image</string>
<string name="dialog_post_video">Video</string> <string name="dialog_post_video">Video</string>
<string name="select_from_gallery">Select a picture</string>
<string name="select_again">Select again</string>
<string name="error_getting_image">Error getting the image</string>
</resources> </resources>