Compare commits
47 Commits
alpha_vers
...
v0.0.5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7e433954c5 | ||
|
|
d47e2dac92 | ||
|
|
de3bea0729 | ||
|
|
3c91007d93 | ||
|
|
debb3e04df | ||
|
|
8c758460bc | ||
|
|
2bb1189e15 | ||
|
|
233fc38c23 | ||
|
|
215d31f8ea | ||
|
|
8ae681c753 | ||
|
|
554eb3c2fe | ||
|
|
c1f8f5a681 | ||
|
|
bb5c82aa60 | ||
|
|
72ba41c940 | ||
|
|
40b6722e66 | ||
|
|
dd3b72bc1f | ||
|
|
e9ecae117d | ||
|
|
5e4793bdaf | ||
|
|
fe351a8466 | ||
|
|
b1b12aba31 | ||
|
|
d2b95e1db6 | ||
|
|
20c317b63f | ||
|
|
f2d14a975d | ||
|
|
442310cad3 | ||
|
|
b8da5c6acb | ||
|
|
2ed15f3d5c | ||
|
|
d926fabe09 | ||
|
|
e815a1444d | ||
|
|
df81866821 | ||
|
|
497f6c79d2 | ||
|
|
6eb585800f | ||
|
|
df842d33e1 | ||
|
|
919d259f61 | ||
|
|
2fc4020b72 | ||
|
|
9d6e15edb7 | ||
|
|
44956bd951 | ||
|
|
388b895499 | ||
|
|
5b26d57fdb | ||
|
|
e2de8b8160 | ||
|
|
f3bff30ef0 | ||
|
|
6704772fb2 | ||
|
|
efc74a074c | ||
|
|
3b5852d1e4 | ||
|
|
0fa2da6ffa | ||
|
|
e3a4db17d2 | ||
|
|
2828429120 | ||
|
|
f2f057827a |
10
README.md
@@ -1,12 +1,12 @@
|
||||
<h1 align="center">
|
||||
|
||||
Infinity for Lemmy
|
||||
</h1>
|
||||
|
||||
<div align="center">
|
||||
|
||||
A Lemmy client on Android written in Java. It's a fork of the [Infinity for Reddit](https://github.com/Docile-Alligator/Infinity-For-Reddit) project, currenty in early development.
|
||||
A Lemmy client for Android written in Java. It's a fork of the [Infinity for Reddit](https://github.com/Docile-Alligator/Infinity-For-Reddit) project, currenty in early development.
|
||||
|
||||
<img align="right" src="https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy/raw/branch/master/fastlane/metadata/android/en-US/images/LemmInfinity.png" width=200>
|
||||
<img align="right" src="https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy/raw/branch/master/fastlane/metadata/android/en-US/images/icon.png" width=200>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -33,9 +33,9 @@ A Lemmy client on Android written in Java. It's a fork of the [Infinity for Redd
|
||||
|
||||
---
|
||||
|
||||
## Action Items for LemmInfinity
|
||||
## Action Items for Infinity for Lemmy
|
||||
|
||||
LemmInfinity is currently in the early stages of development. Expect many unfinished features and bugs!
|
||||
Infinity for Lemmy is currently in the early stages of development. Expect many unfinished features and bugs!
|
||||
|
||||
- [x] Implementation of basic post browsing feature
|
||||
- [x] Support for multiple account handling
|
||||
|
||||
@@ -8,8 +8,8 @@ android {
|
||||
applicationId "eu.toldi.infinityforlemmy"
|
||||
minSdk 21
|
||||
targetSdk 33
|
||||
versionCode 122
|
||||
versionName "0.0.2"
|
||||
versionCode 125
|
||||
versionName "0.0.5"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
javaCompileOptions {
|
||||
annotationProcessorOptions {
|
||||
|
||||
@@ -291,18 +291,70 @@
|
||||
|
||||
<data android:scheme="https" />
|
||||
<data android:scheme="http" />
|
||||
<data android:host="www.reddit.com" />
|
||||
<data android:host="reddit.com" />
|
||||
<data android:host="v.redd.it" />
|
||||
<data android:host="amp.reddit.com" />
|
||||
<data android:host="m.reddit.com" />
|
||||
<data android:host="old.reddit.com" />
|
||||
<data android:host="new.reddit.com" />
|
||||
<data android:host="np.reddit.com" />
|
||||
<data android:host="reddit.app.link" />
|
||||
<data android:host="redd.it" />
|
||||
<data android:host="s.reddit.com" />
|
||||
<data android:host="click.redditmail.com" />
|
||||
<data android:host="lemmy.world" />
|
||||
<data android:host="lemmy.ml" />
|
||||
<data android:host="beehaw.org" />
|
||||
<data android:host="lemm.ee" />
|
||||
<data android:host="sh.itjust.works" />
|
||||
<data android:host="feddit.de" />
|
||||
<data android:host="lemmy.fmhy.ml" />
|
||||
<data android:host="lemmy.ca" />
|
||||
<data android:host="www.hexbear.net" />
|
||||
<data android:host="programming.dev" />
|
||||
<data android:host="lemmy.dbzer0.com" />
|
||||
<data android:host="lemmy.blahaj.zone" />
|
||||
<data android:host="lemmy.one" />
|
||||
<data android:host="vlemmy.net" />
|
||||
<data android:host="lemmy.sdf.org" />
|
||||
<data android:host="discuss.tchncs.de" />
|
||||
<data android:host="lemmygrad.ml" />
|
||||
<data android:host="sopuli.xyz" />
|
||||
<data android:host="reddthat.com" />
|
||||
<data android:host="aussie.zone" />
|
||||
<data android:host="feddit.uk" />
|
||||
<data android:host="feddit.nl" />
|
||||
<data android:host="midwest.social" />
|
||||
<data android:host="infosec.pub" />
|
||||
<data android:host="feddit.it" />
|
||||
<data android:host="ttrpg.network" />
|
||||
<data android:host="pawb.social" />
|
||||
<data android:host="lemmy.zip" />
|
||||
<data android:host="startrek.website" />
|
||||
<data android:host="burggit.moe" />
|
||||
<data android:host="slrpnk.net" />
|
||||
<data android:host="mander.xyz" />
|
||||
<data android:host="lemmy.eco.br" />
|
||||
<data android:host="lemmy.nz" />
|
||||
<data android:host="dormi.zone" />
|
||||
<data android:host="exploding-heads.com" />
|
||||
<data android:host="delraymisfitsboard.com" />
|
||||
<data android:host="monyet.cc" />
|
||||
<data android:host="feddit.dk" />
|
||||
<data android:host="lemmy.pt" />
|
||||
<data android:host="szmer.info" />
|
||||
<data android:host="yiffit.net" />
|
||||
<data android:host="geddit.social" />
|
||||
<data android:host="waveform.social" />
|
||||
<data android:host="discuss.online" />
|
||||
<data android:host="monero.town" />
|
||||
<data android:host="feddit.cl" />
|
||||
<data android:host="iusearchlinux.fyi" />
|
||||
<data android:host="dataterm.digital" />
|
||||
<data android:host="lemmy.whynotdrs.org" />
|
||||
<data android:host="feddit.ch" />
|
||||
<data android:host="enterprise.lemmy.ml" />
|
||||
<data android:host="lemmy.run" />
|
||||
<data android:host="jlai.lu" />
|
||||
<data android:host="pornlemmy.com" />
|
||||
<data android:host="lemdro.id" />
|
||||
<data android:host="lemmyrs.org" />
|
||||
<data android:host="latte.isnot.coffee" />
|
||||
<data android:host="feddit.nu" />
|
||||
<data android:host="lemmy.film" />
|
||||
<data android:host="bakchodi.org" />
|
||||
<data android:host="mujico.org" />
|
||||
<data android:host="lemmy.studio" />
|
||||
<data android:host="lemmy.toldi.eu" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
||||
@@ -12,13 +12,19 @@ public class RetrofitHolder {
|
||||
|
||||
private Retrofit retrofit;
|
||||
private OkHttpClient okHttpClient;
|
||||
private String baseURL = APIUtils.API_BASE_URI;
|
||||
|
||||
public Retrofit getRetrofit() {
|
||||
return retrofit;
|
||||
}
|
||||
|
||||
public void setBaseURL(String baseURL){
|
||||
retrofit = createRetrofit(okHttpClient,baseURL);
|
||||
public void setBaseURL(String baseURL) {
|
||||
retrofit = createRetrofit(okHttpClient, baseURL);
|
||||
this.baseURL = baseURL;
|
||||
}
|
||||
|
||||
public String getBaseURL() {
|
||||
return baseURL;
|
||||
}
|
||||
|
||||
public RetrofitHolder(OkHttpClient okHttpClient) {
|
||||
|
||||
53
app/src/main/java/eu/toldi/infinityforlemmy/SaveComment.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package eu.toldi.infinityforlemmy;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||
import eu.toldi.infinityforlemmy.dto.SaveCommentDTO;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class SaveComment implements SaveThing {
|
||||
@Override
|
||||
public void saveThing(Retrofit retrofit, String accessToken, int id, SaveThingListener saveThingListener) {
|
||||
|
||||
retrofit.create(LemmyAPI.class).commentSave(new SaveCommentDTO(id, true, accessToken)).enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
saveThingListener.success();
|
||||
} else {
|
||||
saveThingListener.failed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||
saveThingListener.failed();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsaveThing(Retrofit retrofit, String accessToken, int id, SaveThingListener saveThingListener) {
|
||||
|
||||
retrofit.create(LemmyAPI.class).commentSave(new SaveCommentDTO(id, false, accessToken)).enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
saveThingListener.success();
|
||||
} else {
|
||||
saveThingListener.failed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||
saveThingListener.failed();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
55
app/src/main/java/eu/toldi/infinityforlemmy/SavePost.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package eu.toldi.infinityforlemmy;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||
import eu.toldi.infinityforlemmy.dto.SavePostDTO;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class SavePost implements SaveThing {
|
||||
|
||||
@Override
|
||||
public void saveThing(Retrofit retrofit, String accessToken, int id, SaveThingListener saveThingListener) {
|
||||
|
||||
|
||||
retrofit.create(LemmyAPI.class).postSave(new SavePostDTO(id, true, accessToken)).enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
saveThingListener.success();
|
||||
} else {
|
||||
saveThingListener.failed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||
saveThingListener.failed();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsaveThing(Retrofit retrofit, String accessToken, int id, SaveThingListener saveThingListener) {
|
||||
|
||||
retrofit.create(LemmyAPI.class).postSave(new SavePostDTO(id, false, accessToken)).enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
saveThingListener.success();
|
||||
} else {
|
||||
saveThingListener.failed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||
saveThingListener.failed();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,59 +1,13 @@
|
||||
package eu.toldi.infinityforlemmy;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class SaveThing {
|
||||
public static void saveThing(Retrofit oauthRetrofit, String accessToken, String fullname,
|
||||
SaveThingListener saveThingListener) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put(APIUtils.ID_KEY, fullname);
|
||||
oauthRetrofit.create(RedditAPI.class).save(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
saveThingListener.success();
|
||||
} else {
|
||||
saveThingListener.failed();
|
||||
}
|
||||
}
|
||||
public interface SaveThing {
|
||||
void saveThing(Retrofit oauthRetrofit, String accessToken, int id,
|
||||
SaveThingListener saveThingListener);
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||
saveThingListener.failed();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void unsaveThing(Retrofit oauthRetrofit, String accessToken, String fullname,
|
||||
SaveThingListener saveThingListener) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put(APIUtils.ID_KEY, fullname);
|
||||
oauthRetrofit.create(RedditAPI.class).unsave(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
saveThingListener.success();
|
||||
} else {
|
||||
saveThingListener.failed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||
saveThingListener.failed();
|
||||
}
|
||||
});
|
||||
}
|
||||
void unsaveThing(Retrofit oauthRetrofit, String accessToken, int id,
|
||||
SaveThingListener saveThingListener);
|
||||
|
||||
public interface SaveThingListener {
|
||||
void success();
|
||||
|
||||
@@ -39,17 +39,10 @@ import java.util.concurrent.Executor;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import io.noties.markwon.AbstractMarkwonPlugin;
|
||||
import io.noties.markwon.Markwon;
|
||||
import io.noties.markwon.MarkwonConfiguration;
|
||||
import io.noties.markwon.MarkwonPlugin;
|
||||
import io.noties.markwon.core.MarkwonTheme;
|
||||
import io.noties.markwon.recycler.MarkwonAdapter;
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||
import eu.toldi.infinityforlemmy.Infinity;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import eu.toldi.infinityforlemmy.UploadImageEnabledActivity;
|
||||
import eu.toldi.infinityforlemmy.UploadedImage;
|
||||
import eu.toldi.infinityforlemmy.account.Account;
|
||||
@@ -66,6 +59,13 @@ import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.markdown.MarkdownUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
import io.noties.markwon.AbstractMarkwonPlugin;
|
||||
import io.noties.markwon.Markwon;
|
||||
import io.noties.markwon.MarkwonConfiguration;
|
||||
import io.noties.markwon.MarkwonPlugin;
|
||||
import io.noties.markwon.core.MarkwonTheme;
|
||||
import io.noties.markwon.recycler.MarkwonAdapter;
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class CommentActivity extends BaseActivity implements UploadImageEnabledActivity, AccountChooserBottomSheetFragment.AccountChooserListener {
|
||||
@@ -449,10 +449,10 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
|
||||
Toast.makeText(CommentActivity.this, R.string.error_getting_image, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
Utils.uploadImageToReddit(this, mExecutor, mRetrofit.getRetrofit(), mUploadMediaRetrofit,
|
||||
Utils.uploadImageToReddit(this, mExecutor, mRetrofit,
|
||||
mAccessToken, binding.commentCommentEditText, binding.commentCoordinatorLayout, data.getData(), uploadedImages);
|
||||
} else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) {
|
||||
Utils.uploadImageToReddit(this, mExecutor, mRetrofit.getRetrofit(), mUploadMediaRetrofit,
|
||||
Utils.uploadImageToReddit(this, mExecutor, mRetrofit,
|
||||
mAccessToken, binding.commentCommentEditText, binding.commentCoordinatorLayout, capturedImageUri, uploadedImages);
|
||||
} else if (requestCode == MARKDOWN_PREVIEW_REQUEST_CODE) {
|
||||
sendComment(mMenu == null ? null : mMenu.findItem(R.id.action_send_comment_activity));
|
||||
|
||||
@@ -32,8 +32,6 @@ import org.greenrobot.eventbus.Subscribe;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -43,15 +41,16 @@ import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.toldi.infinityforlemmy.Infinity;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import eu.toldi.infinityforlemmy.UploadImageEnabledActivity;
|
||||
import eu.toldi.infinityforlemmy.UploadedImage;
|
||||
import eu.toldi.infinityforlemmy.adapters.MarkdownBottomBarRecyclerViewAdapter;
|
||||
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||
import eu.toldi.infinityforlemmy.bottomsheetfragments.UploadedImagesBottomSheetFragment;
|
||||
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
|
||||
import eu.toldi.infinityforlemmy.dto.EditCommentDTO;
|
||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
import retrofit2.Call;
|
||||
@@ -84,8 +83,8 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
|
||||
@BindView(R.id.markdown_bottom_bar_recycler_view_edit_comment_activity)
|
||||
RecyclerView markdownBottomBarRecyclerView;
|
||||
@Inject
|
||||
@Named("oauth")
|
||||
Retrofit mOauthRetrofit;
|
||||
@Named("no_oauth")
|
||||
RetrofitHolder retrofit;
|
||||
@Inject
|
||||
@Named("upload_media")
|
||||
Retrofit mUploadMediaRetrofit;
|
||||
@@ -99,7 +98,7 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
|
||||
CustomThemeWrapper mCustomThemeWrapper;
|
||||
@Inject
|
||||
Executor mExecutor;
|
||||
private String mFullName;
|
||||
private int mCommentId;
|
||||
private String mAccessToken;
|
||||
private String mCommentContent;
|
||||
private boolean isSubmitting = false;
|
||||
@@ -129,7 +128,10 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
mFullName = getIntent().getStringExtra(EXTRA_FULLNAME);
|
||||
mCommentId = getIntent().getIntExtra(EXTRA_FULLNAME, 0);
|
||||
if (mCommentId == 0) {
|
||||
finish();
|
||||
}
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
mCommentContent = getIntent().getStringExtra(EXTRA_CONTENT);
|
||||
contentEditText.setText(mCommentContent);
|
||||
@@ -225,12 +227,7 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
|
||||
|
||||
String content = contentEditText.getText().toString();
|
||||
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put(APIUtils.THING_ID_KEY, mFullName);
|
||||
params.put(APIUtils.TEXT_KEY, content);
|
||||
|
||||
mOauthRetrofit.create(RedditAPI.class)
|
||||
.editPostOrComment(APIUtils.getOAuthHeader(mAccessToken), params)
|
||||
retrofit.getRetrofit().create(LemmyAPI.class).commentEdit(new EditCommentDTO(mCommentId, content, null, null, mAccessToken))
|
||||
.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
@@ -278,10 +275,10 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
|
||||
Toast.makeText(EditCommentActivity.this, R.string.error_getting_image, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
|
||||
Utils.uploadImageToReddit(this, mExecutor, retrofit,
|
||||
mAccessToken, contentEditText, coordinatorLayout, data.getData(), uploadedImages);
|
||||
} else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) {
|
||||
Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
|
||||
Utils.uploadImageToReddit(this, mExecutor, retrofit,
|
||||
mAccessToken, contentEditText, coordinatorLayout, capturedImageUri, uploadedImages);
|
||||
} else if (requestCode == MARKDOWN_PREVIEW_REQUEST_CODE) {
|
||||
editComment();
|
||||
|
||||
@@ -44,6 +44,7 @@ import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.toldi.infinityforlemmy.Infinity;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import eu.toldi.infinityforlemmy.UploadImageEnabledActivity;
|
||||
import eu.toldi.infinityforlemmy.UploadedImage;
|
||||
import eu.toldi.infinityforlemmy.adapters.MarkdownBottomBarRecyclerViewAdapter;
|
||||
@@ -88,8 +89,8 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled
|
||||
@BindView(R.id.markdown_bottom_bar_recycler_view_edit_post_activity)
|
||||
RecyclerView markdownBottomBarRecyclerView;
|
||||
@Inject
|
||||
@Named("oauth")
|
||||
Retrofit mOauthRetrofit;
|
||||
@Named("no_oauth")
|
||||
RetrofitHolder mRetrofit;
|
||||
@Inject
|
||||
@Named("upload_media")
|
||||
Retrofit mUploadMediaRetrofit;
|
||||
@@ -241,7 +242,7 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled
|
||||
params.put(APIUtils.THING_ID_KEY, mFullName);
|
||||
params.put(APIUtils.TEXT_KEY, contentEditText.getText().toString());
|
||||
|
||||
mOauthRetrofit.create(RedditAPI.class)
|
||||
mRetrofit.getRetrofit().create(RedditAPI.class)
|
||||
.editPostOrComment(APIUtils.getOAuthHeader(mAccessToken), params)
|
||||
.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
@@ -272,10 +273,10 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled
|
||||
Toast.makeText(EditPostActivity.this, R.string.error_getting_image, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
|
||||
Utils.uploadImageToReddit(this, mExecutor, mRetrofit,
|
||||
mAccessToken, contentEditText, coordinatorLayout, data.getData(), uploadedImages);
|
||||
} else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) {
|
||||
Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
|
||||
Utils.uploadImageToReddit(this, mExecutor, mRetrofit,
|
||||
mAccessToken, contentEditText, coordinatorLayout, capturedImageUri, uploadedImages);
|
||||
} else if (requestCode == MARKDOWN_PREVIEW_REQUEST_CODE) {
|
||||
editPost();
|
||||
|
||||
@@ -64,7 +64,6 @@ import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class InboxActivity extends BaseActivity implements ActivityToolbarInterface, RecyclerViewContentScrollingInterface {
|
||||
|
||||
@@ -93,9 +92,6 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
|
||||
@Named("base")
|
||||
RetrofitHolder mRetrofit;
|
||||
|
||||
@Inject
|
||||
@Named("oauth")
|
||||
Retrofit mOauthRetrofit;
|
||||
@Inject
|
||||
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||
@Inject
|
||||
@@ -307,7 +303,7 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
|
||||
} else if (item.getItemId() == R.id.action_read_all_messages_inbox_activity) {
|
||||
if (mAccessToken != null) {
|
||||
Toast.makeText(this, R.string.please_wait, Toast.LENGTH_SHORT).show();
|
||||
mOauthRetrofit.create(RedditAPI.class).readAllMessages(APIUtils.getOAuthHeader(mAccessToken))
|
||||
mRetrofit.getRetrofit().create(RedditAPI.class).readAllMessages(APIUtils.getOAuthHeader(mAccessToken))
|
||||
.enqueue(new Callback<>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
|
||||
@@ -21,11 +21,11 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -139,9 +139,9 @@ public class LoginActivity extends BaseActivity {
|
||||
Log.i("LoginActivity", "Login button clicked");
|
||||
loginButton.setEnabled(false);
|
||||
progressBar.setVisibility(ProgressBar.VISIBLE);
|
||||
String username = username_input.getText().toString();
|
||||
String instance = correctURL(instance_input.getText().toString());
|
||||
if(!Patterns.WEB_URL.matcher(instance).matches()){
|
||||
String username = username_input.getText().toString().trim();
|
||||
String instance = correctURL(instance_input.getText().toString().trim());
|
||||
if (!Patterns.WEB_URL.matcher(instance).matches()) {
|
||||
instance_input.setError("Invalid instance URL");
|
||||
Toast.makeText(LoginActivity.this, "Invalid instance URL", Toast.LENGTH_SHORT).show();
|
||||
loginButton.setEnabled(true);
|
||||
@@ -149,7 +149,7 @@ public class LoginActivity extends BaseActivity {
|
||||
return;
|
||||
}
|
||||
Log.i("LoginActivity", "Instance: " + instance);
|
||||
AccountLoginDTO accountLoginDTO = new AccountLoginDTO(username,password_input.getText().toString(),token_2fa_input.getText().toString());
|
||||
AccountLoginDTO accountLoginDTO = new AccountLoginDTO(username, password_input.getText().toString(), token_2fa_input.getText().toString());
|
||||
mRetrofit.setBaseURL(instance);
|
||||
LemmyAPI api = mRetrofit.getRetrofit().create(LemmyAPI.class);
|
||||
Call<String> accessTokenCall = api.userLogin(accountLoginDTO);
|
||||
@@ -158,14 +158,16 @@ public class LoginActivity extends BaseActivity {
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
progressBar.setVisibility(ProgressBar.GONE);
|
||||
loginButton.setEnabled(true);
|
||||
String accountResponse = response.body();
|
||||
if (accountResponse == null) {
|
||||
Log.e("LoginActivity", "Account response is null");
|
||||
Toast.makeText(LoginActivity.this, R.string.cannot_fetch_user_info, Toast.LENGTH_SHORT).show();
|
||||
//Handle error
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (response.isSuccessful()) {
|
||||
String accountResponse = response.body();
|
||||
if (accountResponse == null) {
|
||||
Log.e("LoginActivity", "Account response is null");
|
||||
Toast.makeText(LoginActivity.this, R.string.invalid_response, Toast.LENGTH_SHORT).show();
|
||||
//Handle error
|
||||
return;
|
||||
}
|
||||
try {
|
||||
JSONObject responseJSON = new JSONObject(accountResponse);
|
||||
String accessToken = responseJSON.getString("jwt");
|
||||
@@ -173,7 +175,7 @@ public class LoginActivity extends BaseActivity {
|
||||
FetchMyInfo.fetchAccountInfo(mRetrofit.getRetrofit(), mRedditDataRoomDatabase, username,
|
||||
accessToken, new FetchMyInfo.FetchMyInfoListener() {
|
||||
@Override
|
||||
public void onFetchMyInfoSuccess(String name,String display_name, String profileImageUrl, String bannerImageUrl) {
|
||||
public void onFetchMyInfoSuccess(String name, String display_name, String profileImageUrl, String bannerImageUrl) {
|
||||
mCurrentAccountSharedPreferences.edit().putString(SharedPreferencesUtils.ACCESS_TOKEN, accessToken)
|
||||
.putString(SharedPreferencesUtils.ACCOUNT_NAME, display_name)
|
||||
.putString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, name)
|
||||
@@ -206,18 +208,25 @@ public class LoginActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject responseObject = new JSONObject(accountResponse);
|
||||
if(responseObject.has("error")) {
|
||||
Toast.makeText(LoginActivity.this, "Error:"+responseObject.getString("error"), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
else {
|
||||
String errorBody = response.errorBody().string();
|
||||
Log.e("LoginActivity", "Error body: " + errorBody.trim());
|
||||
JSONObject responseObject = new JSONObject(errorBody.trim());
|
||||
if (responseObject.has("error")) {
|
||||
if (responseObject.getString("error").equals("incorrect_login")) {
|
||||
Toast.makeText(LoginActivity.this, R.string.invalid_username_or_password, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(LoginActivity.this, "Error:" + responseObject.getString("error"), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(LoginActivity.this, R.string.cannot_fetch_user_info, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Toast.makeText(LoginActivity.this, R.string.cannot_fetch_user_info, Toast.LENGTH_SHORT).show();
|
||||
} catch (IOException e) {
|
||||
Toast.makeText(LoginActivity.this, R.string.cannot_fetch_user_info, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
Log.e("LoginActivity", "Failed to get access token: " + response.code() + " " + response.message() + " " + response.errorBody());
|
||||
Log.e("LoginActivity", "Failed to get access token: " + response.code() + " " + response.message());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,8 @@ import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
@@ -71,7 +73,6 @@ import javax.inject.Named;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.toldi.infinityforlemmy.ActivityToolbarInterface;
|
||||
import eu.toldi.infinityforlemmy.FetchMyInfo;
|
||||
import eu.toldi.infinityforlemmy.FetchSubscribedThing;
|
||||
import eu.toldi.infinityforlemmy.Infinity;
|
||||
import eu.toldi.infinityforlemmy.MarkPostAsReadInterface;
|
||||
@@ -326,9 +327,10 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
fragmentManager = getSupportFragmentManager();
|
||||
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
|
||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||
mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
|
||||
String instance = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_INSTANCE, null);
|
||||
String instance = (mAccessToken == null) ? mSharedPreferences.getString(SharedPreferencesUtils.ANONYMOUS_ACCOUNT_INSTANCE, APIUtils.API_BASE_URI) : mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_INSTANCE, null);
|
||||
if(instance != null) {
|
||||
mRetrofit.setBaseURL(instance);
|
||||
}
|
||||
@@ -349,6 +351,17 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
initializeNotificationAndBindView();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (mAccessToken == null) {
|
||||
String instancePreference = mSharedPreferences.getString(SharedPreferencesUtils.ANONYMOUS_ACCOUNT_INSTANCE, APIUtils.API_BASE_URI);
|
||||
if (!mRetrofit.getBaseURL().equalsIgnoreCase(instancePreference)) {
|
||||
this.recreate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SharedPreferences getDefaultSharedPreferences() {
|
||||
return mSharedPreferences;
|
||||
@@ -859,6 +872,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
startActivity(logOutIntent);
|
||||
finish();
|
||||
});
|
||||
} else if (stringId == R.string.anonymous_account_instance) {
|
||||
changeAnonymousAccountInstance();
|
||||
}
|
||||
if (intent != null) {
|
||||
startActivity(intent);
|
||||
@@ -1386,6 +1401,72 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
}
|
||||
}
|
||||
|
||||
private void changeAnonymousAccountInstance() {
|
||||
View rootView = getLayoutInflater().inflate(R.layout.dialog_go_to_thing_edit_text, coordinatorLayout, false);
|
||||
TextInputEditText thingEditText = rootView.findViewById(R.id.text_input_edit_text_go_to_thing_edit_text);
|
||||
|
||||
thingEditText.requestFocus();
|
||||
thingEditText.setText(mSharedPreferences.getString(SharedPreferencesUtils.ANONYMOUS_ACCOUNT_INSTANCE, APIUtils.API_BASE_URI));
|
||||
Utils.showKeyboard(this, new Handler(), thingEditText);
|
||||
thingEditText.setOnEditorActionListener((textView, i, keyEvent) -> {
|
||||
if (i == EditorInfo.IME_ACTION_DONE) {
|
||||
Utils.hideKeyboard(this);
|
||||
String url = thingEditText.getText().toString();
|
||||
if (url.isEmpty()) {
|
||||
thingEditText.setError("Instance URL cannot be empty");
|
||||
return false;
|
||||
}
|
||||
if (!url.startsWith("http://") || !url.startsWith("https://")) {
|
||||
url = "https://" + url;
|
||||
}
|
||||
try {
|
||||
URL urlObj = new URL(url);
|
||||
url = urlObj.getProtocol() + "://" + urlObj.getHost() + "/";
|
||||
mSharedPreferences.edit().putString(SharedPreferencesUtils.ANONYMOUS_ACCOUNT_INSTANCE, url).apply();
|
||||
mRetrofit.setBaseURL(url);
|
||||
sectionsPagerAdapter.getCurrentFragment().refresh();
|
||||
} catch (MalformedURLException e) {
|
||||
thingEditText.setError("Invalid URL");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
|
||||
.setTitle(R.string.anonymous_account_instance)
|
||||
.setView(rootView)
|
||||
.setPositiveButton(R.string.ok, (dialogInterface, i)
|
||||
-> {
|
||||
Utils.hideKeyboard(this);
|
||||
String url = thingEditText.getText().toString();
|
||||
if (url.isEmpty()) {
|
||||
thingEditText.setError("Instance URL cannot be empty");
|
||||
return;
|
||||
}
|
||||
if (!url.startsWith("http://") && !url.startsWith("https://")) {
|
||||
url = "https://" + url;
|
||||
}
|
||||
try {
|
||||
URL urlObj = new URL(url);
|
||||
url = urlObj.getProtocol() + "://" + urlObj.getHost() + "/";
|
||||
mSharedPreferences.edit().putString(SharedPreferencesUtils.ANONYMOUS_ACCOUNT_INSTANCE, url).apply();
|
||||
mRetrofit.setBaseURL(url);
|
||||
sectionsPagerAdapter.getCurrentFragment().refresh();
|
||||
} catch (MalformedURLException e) {
|
||||
thingEditText.setError("Invalid URL");
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
|
||||
Utils.hideKeyboard(this);
|
||||
})
|
||||
.setOnDismissListener(dialogInterface -> {
|
||||
Utils.hideKeyboard(this);
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
private void goToSubreddit() {
|
||||
View rootView = getLayoutInflater().inflate(R.layout.dialog_go_to_thing_edit_text, coordinatorLayout, false);
|
||||
TextInputEditText thingEditText = rootView.findViewById(R.id.text_input_edit_text_go_to_thing_edit_text);
|
||||
@@ -1406,7 +1487,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
if (i == EditorInfo.IME_ACTION_DONE) {
|
||||
Utils.hideKeyboard(this);
|
||||
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
|
||||
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString());
|
||||
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, thingEditText.getText().toString());
|
||||
startActivity(subredditIntent);
|
||||
return true;
|
||||
}
|
||||
@@ -1464,7 +1545,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
-> {
|
||||
Utils.hideKeyboard(this);
|
||||
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
|
||||
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString());
|
||||
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, thingEditText.getText().toString());
|
||||
startActivity(subredditIntent);
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
|
||||
@@ -1485,7 +1566,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
if (i == EditorInfo.IME_ACTION_DONE) {
|
||||
Utils.hideKeyboard(this);
|
||||
Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
|
||||
userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString());
|
||||
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, thingEditText.getText().toString());
|
||||
startActivity(userIntent);
|
||||
return true;
|
||||
}
|
||||
@@ -1498,7 +1579,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
-> {
|
||||
Utils.hideKeyboard(this);
|
||||
Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
|
||||
userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString());
|
||||
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, thingEditText.getText().toString());
|
||||
startActivity(userIntent);
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
|
||||
@@ -1649,7 +1730,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
} else if (postType == SharedPreferencesUtils.MAIN_PAGE_TAB_POST_TYPE_ALL) {
|
||||
PostFragment fragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, mAccessToken == null ? PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE : PostPagingSource.TYPE_FRONT_PAGE);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_FRONT_PAGE);
|
||||
bundle.putString(PostFragment.EXTRA_NAME, "all");
|
||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||
@@ -1713,7 +1794,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
} else {
|
||||
PostFragment fragment = new PostFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, mAccessToken == null ? PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE : PostPagingSource.TYPE_FRONT_PAGE);
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_FRONT_PAGE);
|
||||
bundle.putString(PostFragment.EXTRA_NAME, "local");
|
||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||
|
||||
@@ -74,6 +74,9 @@ import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.events.SubmitGalleryPostEvent;
|
||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.services.SubmitPostService;
|
||||
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.JSONUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.UploadImageUtils;
|
||||
@@ -102,6 +105,7 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
||||
private static final int PICK_IMAGE_REQUEST_CODE = 1;
|
||||
private static final int CAPTURE_IMAGE_REQUEST_CODE = 2;
|
||||
private static final String COMMUNITY_DATA_STATE = "CDS";
|
||||
|
||||
@BindView(R.id.coordinator_layout_post_gallery_activity)
|
||||
CoordinatorLayout coordinatorLayout;
|
||||
@@ -123,10 +127,6 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
MaterialButton rulesButton;
|
||||
@BindView(R.id.divider_1_post_gallery_activity)
|
||||
MaterialDivider divider1;
|
||||
@BindView(R.id.flair_custom_text_view_post_gallery_activity)
|
||||
CustomTextView flairTextView;
|
||||
@BindView(R.id.spoiler_custom_text_view_post_gallery_activity)
|
||||
CustomTextView spoilerTextView;
|
||||
@BindView(R.id.nsfw_custom_text_view_post_gallery_activity)
|
||||
CustomTextView nsfwTextView;
|
||||
@BindView(R.id.receive_post_reply_notifications_linear_layout_post_gallery_activity)
|
||||
@@ -168,6 +168,7 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
private String mAccountName;
|
||||
private String iconUrl;
|
||||
private String subredditName;
|
||||
private SubscribedSubredditData communityData;
|
||||
private boolean subredditSelected = false;
|
||||
private boolean subredditIsUser;
|
||||
private boolean loadSubredditIconSuccessful = true;
|
||||
@@ -245,6 +246,7 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
selectedAccount = savedInstanceState.getParcelable(SELECTED_ACCOUNT_STATE);
|
||||
communityData = savedInstanceState.getParcelable(COMMUNITY_DATA_STATE);
|
||||
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
||||
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
|
||||
subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
|
||||
@@ -279,7 +281,6 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
if (subredditName != null) {
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
if (!loadSubredditIconSuccessful) {
|
||||
loadSubredditIcon();
|
||||
}
|
||||
@@ -290,17 +291,6 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
mPostingSnackbar.show();
|
||||
}
|
||||
|
||||
if (flair != null) {
|
||||
flairTextView.setText(flair.getText());
|
||||
flairTextView.setBackgroundColor(flairBackgroundColor);
|
||||
flairTextView.setBorderColor(flairBackgroundColor);
|
||||
flairTextView.setTextColor(flairTextColor);
|
||||
}
|
||||
if (isSpoiler) {
|
||||
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setBorderColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setTextColor(spoilerTextColor);
|
||||
}
|
||||
if (isNSFW) {
|
||||
nsfwTextView.setBackgroundColor(nsfwBackgroundColor);
|
||||
nsfwTextView.setBorderColor(nsfwBackgroundColor);
|
||||
@@ -314,11 +304,25 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
||||
loadSubredditIconSuccessful = false;
|
||||
subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
|
||||
subredditSelected = true;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
loadSubredditIcon();
|
||||
FetchSubredditData.fetchSubredditData(mRetrofit.getRetrofit(), subredditName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
{
|
||||
communityData = new SubscribedSubredditData(subredditData);
|
||||
subredditName = communityData.getName();
|
||||
subredditIsUser = false;
|
||||
subredditSelected = true;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
loadSubredditIcon();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchSubredditDataFail(boolean isQuarantined) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mGlide.load(R.drawable.subreddit_default_icon)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||
@@ -347,40 +351,12 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
if (subredditIsUser) {
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, "u_" + subredditName);
|
||||
} else {
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, communityData.getQualified_name());
|
||||
}
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
flairTextView.setOnClickListener(view -> {
|
||||
if (flair == null) {
|
||||
flairSelectionBottomSheetFragment = new FlairBottomSheetFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
flairSelectionBottomSheetFragment.setArguments(bundle);
|
||||
flairSelectionBottomSheetFragment.show(getSupportFragmentManager(), flairSelectionBottomSheetFragment.getTag());
|
||||
} else {
|
||||
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
flairTextView.setText(getString(R.string.flair));
|
||||
flair = null;
|
||||
}
|
||||
});
|
||||
|
||||
spoilerTextView.setOnClickListener(view -> {
|
||||
if (!isSpoiler) {
|
||||
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setBorderColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setTextColor(spoilerTextColor);
|
||||
isSpoiler = true;
|
||||
} else {
|
||||
spoilerTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
spoilerTextView.setTextColor(primaryTextColor);
|
||||
isSpoiler = false;
|
||||
}
|
||||
});
|
||||
|
||||
nsfwTextView.setOnClickListener(view -> {
|
||||
if (!isNSFW) {
|
||||
@@ -449,8 +425,7 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
spoilerTextColor = mCustomThemeWrapper.getSpoilerTextColor();
|
||||
nsfwBackgroundColor = mCustomThemeWrapper.getNsfwBackgroundColor();
|
||||
nsfwTextColor = mCustomThemeWrapper.getNsfwTextColor();
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
spoilerTextView.setTextColor(primaryTextColor);
|
||||
|
||||
nsfwTextView.setTextColor(primaryTextColor);
|
||||
titleEditText.setTextColor(primaryTextColor);
|
||||
titleEditText.setHintTextColor(secondaryTextColor);
|
||||
@@ -458,8 +433,6 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
subredditNameTextView.setTypeface(typeface);
|
||||
rulesButton.setTypeface(typeface);
|
||||
receivePostReplyNotificationsTextView.setTypeface(typeface);
|
||||
flairTextView.setTypeface(typeface);
|
||||
spoilerTextView.setTypeface(typeface);
|
||||
nsfwTextView.setTypeface(typeface);
|
||||
titleEditText.setTypeface(typeface);
|
||||
}
|
||||
@@ -492,7 +465,7 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
mExecutor.execute(() -> {
|
||||
try {
|
||||
Bitmap resource = Glide.with(PostGalleryActivity.this).asBitmap().load(imageUri).submit().get();
|
||||
String response = UploadImageUtils.uploadImage(mOauthRetrofit, mUploadMediaRetrofit, mAccessToken, resource, true);
|
||||
String response = UploadImageUtils.uploadImage(mRetrofit, mAccessToken, resource, true);
|
||||
String mediaId = new JSONObject(response).getJSONObject(JSONUtils.ASSET_KEY).getString(JSONUtils.ASSET_ID_KEY);
|
||||
handler.post(() -> {
|
||||
adapter.setImageAsUploaded(mediaId);
|
||||
@@ -612,7 +585,7 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
|
||||
Intent intent = new Intent(this, SubmitPostService.class);
|
||||
intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, communityData.getId());
|
||||
intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_GALLERY);
|
||||
ArrayList<RedditGalleryPayload.Item> items = new ArrayList<>();
|
||||
for (RedditGallerySubmissionRecyclerViewAdapter.RedditGalleryImageInfo i : redditGalleryImageInfoList) {
|
||||
@@ -648,6 +621,7 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelable(SELECTED_ACCOUNT_STATE, selectedAccount);
|
||||
outState.putParcelable(COMMUNITY_DATA_STATE, communityData);
|
||||
outState.putString(SUBREDDIT_NAME_STATE, subredditName);
|
||||
outState.putString(SUBREDDIT_ICON_STATE, iconUrl);
|
||||
outState.putBoolean(SUBREDDIT_SELECTED_STATE, subredditSelected);
|
||||
@@ -666,19 +640,16 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
subredditName = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
iconUrl = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);
|
||||
communityData = data.getParcelableExtra(SubredditSelectionActivity.EXTRA_RETURN_COMMUNITY_DATA);
|
||||
subredditName = communityData.getName();
|
||||
iconUrl = communityData.getIconUrl();
|
||||
subredditSelected = true;
|
||||
subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER);
|
||||
subredditIsUser = false;
|
||||
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
displaySubredditIcon();
|
||||
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
flairTextView.setText(getString(R.string.flair));
|
||||
flair = null;
|
||||
}
|
||||
} else if (requestCode == PICK_IMAGE_REQUEST_CODE) {
|
||||
@@ -709,10 +680,6 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
@Override
|
||||
public void flairSelected(Flair flair) {
|
||||
this.flair = flair;
|
||||
flairTextView.setText(flair.getText());
|
||||
flairTextView.setBackgroundColor(flairBackgroundColor);
|
||||
flairTextView.setBorderColor(flairBackgroundColor);
|
||||
flairTextView.setTextColor(flairTextColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -64,6 +64,9 @@ import eu.toldi.infinityforlemmy.events.SubmitImagePostEvent;
|
||||
import eu.toldi.infinityforlemmy.events.SubmitVideoOrGifPostEvent;
|
||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.services.SubmitPostService;
|
||||
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||
import pl.droidsonroids.gif.GifImageView;
|
||||
@@ -89,6 +92,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
||||
private static final int PICK_IMAGE_REQUEST_CODE = 1;
|
||||
private static final int CAPTURE_IMAGE_REQUEST_CODE = 2;
|
||||
private static final String COMMUNITY_DATA_STATE = "CDS";
|
||||
|
||||
@BindView(R.id.coordinator_layout_post_image_activity)
|
||||
CoordinatorLayout coordinatorLayout;
|
||||
@@ -110,10 +114,6 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
MaterialButton rulesButton;
|
||||
@BindView(R.id.divider_1_post_image_activity)
|
||||
MaterialDivider divider1;
|
||||
@BindView(R.id.flair_custom_text_view_post_image_activity)
|
||||
CustomTextView flairTextView;
|
||||
@BindView(R.id.spoiler_custom_text_view_post_image_activity)
|
||||
CustomTextView spoilerTextView;
|
||||
@BindView(R.id.nsfw_custom_text_view_post_image_activity)
|
||||
CustomTextView nsfwTextView;
|
||||
@BindView(R.id.receive_post_reply_notifications_linear_layout_post_image_activity)
|
||||
@@ -162,6 +162,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
private String mAccountName;
|
||||
private String iconUrl;
|
||||
private String subredditName;
|
||||
private SubscribedSubredditData communityData;
|
||||
private boolean subredditSelected = false;
|
||||
private boolean subredditIsUser;
|
||||
private boolean loadSubredditIconSuccessful = true;
|
||||
@@ -217,6 +218,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
selectedAccount = savedInstanceState.getParcelable(SELECTED_ACCOUNT_STATE);
|
||||
communityData = savedInstanceState.getParcelable(COMMUNITY_DATA_STATE);
|
||||
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
||||
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
|
||||
subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
|
||||
@@ -247,7 +249,6 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
if (subredditName != null) {
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
if (!loadSubredditIconSuccessful) {
|
||||
loadSubredditIcon();
|
||||
}
|
||||
@@ -258,17 +259,6 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
mPostingSnackbar.show();
|
||||
}
|
||||
|
||||
if (flair != null) {
|
||||
flairTextView.setText(flair.getText());
|
||||
flairTextView.setBackgroundColor(flairBackgroundColor);
|
||||
flairTextView.setBorderColor(flairBackgroundColor);
|
||||
flairTextView.setTextColor(flairTextColor);
|
||||
}
|
||||
if (isSpoiler) {
|
||||
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setBorderColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setTextColor(spoilerTextColor);
|
||||
}
|
||||
if (isNSFW) {
|
||||
nsfwTextView.setBackgroundColor(nsfwBackgroundColor);
|
||||
nsfwTextView.setBorderColor(nsfwBackgroundColor);
|
||||
@@ -282,11 +272,25 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
||||
loadSubredditIconSuccessful = false;
|
||||
subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
|
||||
subredditSelected = true;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
loadSubredditIcon();
|
||||
FetchSubredditData.fetchSubredditData(mRetrofit.getRetrofit(), subredditName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
{
|
||||
communityData = new SubscribedSubredditData(subredditData);
|
||||
subredditName = communityData.getName();
|
||||
subredditIsUser = false;
|
||||
subredditSelected = true;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
loadSubredditIcon();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchSubredditDataFail(boolean isQuarantined) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mGlide.load(R.drawable.subreddit_default_icon)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||
@@ -320,40 +324,12 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
if (subredditIsUser) {
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, "u_" + subredditName);
|
||||
} else {
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, communityData.getQualified_name());
|
||||
}
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
flairTextView.setOnClickListener(view -> {
|
||||
if (flair == null) {
|
||||
flairSelectionBottomSheetFragment = new FlairBottomSheetFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
flairSelectionBottomSheetFragment.setArguments(bundle);
|
||||
flairSelectionBottomSheetFragment.show(getSupportFragmentManager(), flairSelectionBottomSheetFragment.getTag());
|
||||
} else {
|
||||
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
flairTextView.setText(getString(R.string.flair));
|
||||
flair = null;
|
||||
}
|
||||
});
|
||||
|
||||
spoilerTextView.setOnClickListener(view -> {
|
||||
if (!isSpoiler) {
|
||||
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setBorderColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setTextColor(spoilerTextColor);
|
||||
isSpoiler = true;
|
||||
} else {
|
||||
spoilerTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
spoilerTextView.setTextColor(primaryTextColor);
|
||||
isSpoiler = false;
|
||||
}
|
||||
});
|
||||
|
||||
nsfwTextView.setOnClickListener(view -> {
|
||||
if (!isNSFW) {
|
||||
@@ -451,8 +427,6 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
spoilerTextColor = mCustomThemeWrapper.getSpoilerTextColor();
|
||||
nsfwBackgroundColor = mCustomThemeWrapper.getNsfwBackgroundColor();
|
||||
nsfwTextColor = mCustomThemeWrapper.getNsfwTextColor();
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
spoilerTextView.setTextColor(primaryTextColor);
|
||||
nsfwTextView.setTextColor(primaryTextColor);
|
||||
titleEditText.setTextColor(primaryTextColor);
|
||||
titleEditText.setHintTextColor(secondaryTextColor);
|
||||
@@ -463,8 +437,6 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
subredditNameTextView.setTypeface(typeface);
|
||||
rulesButton.setTypeface(typeface);
|
||||
receivePostReplyNotificationsTextView.setTypeface(typeface);
|
||||
flairTextView.setTypeface(typeface);
|
||||
spoilerTextView.setTypeface(typeface);
|
||||
nsfwTextView.setTypeface(typeface);
|
||||
titleEditText.setTypeface(typeface);
|
||||
selectAgainTextView.setTypeface(typeface);
|
||||
@@ -570,7 +542,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
Intent intent = new Intent(this, SubmitPostService.class);
|
||||
intent.setData(imageUri);
|
||||
intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, communityData.getId());
|
||||
intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
|
||||
intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair);
|
||||
intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler);
|
||||
@@ -608,6 +580,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
@Override
|
||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelable(COMMUNITY_DATA_STATE, communityData);
|
||||
outState.putParcelable(SELECTED_ACCOUNT_STATE, selectedAccount);
|
||||
outState.putString(SUBREDDIT_NAME_STATE, subredditName);
|
||||
outState.putString(SUBREDDIT_ICON_STATE, iconUrl);
|
||||
@@ -628,19 +601,15 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
subredditName = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
iconUrl = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);
|
||||
communityData = data.getExtras().getParcelable(SubredditSelectionActivity.EXTRA_RETURN_COMMUNITY_DATA);
|
||||
subredditName = communityData.getName();
|
||||
iconUrl = communityData.getIconUrl();
|
||||
subredditSelected = true;
|
||||
subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER);
|
||||
|
||||
subredditIsUser = false;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
displaySubredditIcon();
|
||||
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
flairTextView.setText(getString(R.string.flair));
|
||||
flair = null;
|
||||
}
|
||||
} else if (requestCode == PICK_IMAGE_REQUEST_CODE) {
|
||||
@@ -669,10 +638,6 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
@Override
|
||||
public void flairSelected(Flair flair) {
|
||||
this.flair = flair;
|
||||
flairTextView.setText(flair.getText());
|
||||
flairTextView.setBackgroundColor(flairBackgroundColor);
|
||||
flairTextView.setBorderColor(flairBackgroundColor);
|
||||
flairTextView.setTextColor(flairTextColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -700,8 +665,8 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
isPosting = false;
|
||||
mPostingSnackbar.dismiss();
|
||||
if (submitImagePostEvent.postSuccess) {
|
||||
Intent intent = new Intent(PostImageActivity.this, ViewUserDetailActivity.class);
|
||||
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, mAccountName);
|
||||
Intent intent = new Intent(PostImageActivity.this, ViewPostDetailActivity.class);
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_DATA, submitImagePostEvent.post);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
} else {
|
||||
|
||||
@@ -8,7 +8,6 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.webkit.URLUtil;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
@@ -56,6 +55,9 @@ import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.events.SubmitTextOrLinkPostEvent;
|
||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.services.SubmitPostService;
|
||||
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||
@@ -73,6 +75,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
static final String EXTRA_LINK = "EL";
|
||||
|
||||
private static final String SELECTED_ACCOUNT_STATE = "SAS";
|
||||
private static final String COMMUNITY_DATA_STATE = "CDS";
|
||||
private static final String SUBREDDIT_NAME_STATE = "SNS";
|
||||
private static final String SUBREDDIT_ICON_STATE = "SIS";
|
||||
private static final String SUBREDDIT_SELECTED_STATE = "SSS";
|
||||
@@ -107,10 +110,6 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
MaterialDivider divider1;
|
||||
@BindView(R.id.divider_2_post_link_activity)
|
||||
MaterialDivider divider2;
|
||||
@BindView(R.id.flair_custom_text_view_post_link_activity)
|
||||
CustomTextView flairTextView;
|
||||
@BindView(R.id.spoiler_custom_text_view_post_link_activity)
|
||||
CustomTextView spoilerTextView;
|
||||
@BindView(R.id.nsfw_custom_text_view_post_link_activity)
|
||||
CustomTextView nsfwTextView;
|
||||
@BindView(R.id.receive_post_reply_notifications_linear_layout_post_link_activity)
|
||||
@@ -147,6 +146,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
private String mAccessToken;
|
||||
private String iconUrl;
|
||||
private String subredditName;
|
||||
private SubscribedSubredditData communityData;
|
||||
private boolean subredditSelected = false;
|
||||
private boolean subredditIsUser;
|
||||
private boolean loadSubredditIconSuccessful = true;
|
||||
@@ -200,6 +200,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
selectedAccount = savedInstanceState.getParcelable(SELECTED_ACCOUNT_STATE);
|
||||
communityData = savedInstanceState.getParcelable(COMMUNITY_DATA_STATE);
|
||||
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
||||
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
|
||||
subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
|
||||
@@ -225,7 +226,6 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
if (subredditName != null) {
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
if (!loadSubredditIconSuccessful) {
|
||||
loadSubredditIcon();
|
||||
}
|
||||
@@ -236,17 +236,6 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
mPostingSnackbar.show();
|
||||
}
|
||||
|
||||
if (flair != null) {
|
||||
flairTextView.setText(flair.getText());
|
||||
flairTextView.setBackgroundColor(flairBackgroundColor);
|
||||
flairTextView.setBorderColor(flairBackgroundColor);
|
||||
flairTextView.setTextColor(flairTextColor);
|
||||
}
|
||||
if (isSpoiler) {
|
||||
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setBorderColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setTextColor(spoilerTextColor);
|
||||
}
|
||||
if (isNSFW) {
|
||||
nsfwTextView.setBackgroundColor(nsfwBackgroundColor);
|
||||
nsfwTextView.setBorderColor(nsfwBackgroundColor);
|
||||
@@ -260,11 +249,25 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
||||
loadSubredditIconSuccessful = false;
|
||||
subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
|
||||
subredditSelected = true;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
loadSubredditIcon();
|
||||
FetchSubredditData.fetchSubredditData(mRetrofit.getRetrofit(), subredditName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
{
|
||||
communityData = new SubscribedSubredditData(subredditData);
|
||||
subredditName = communityData.getName();
|
||||
subredditIsUser = false;
|
||||
subredditSelected = true;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
loadSubredditIcon();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchSubredditDataFail(boolean isQuarantined) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mGlide.load(R.drawable.subreddit_default_icon)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||
@@ -298,40 +301,12 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
if (subredditIsUser) {
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, "u_" + subredditName);
|
||||
} else {
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, communityData.getQualified_name());
|
||||
}
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
flairTextView.setOnClickListener(view -> {
|
||||
if (flair == null) {
|
||||
flairSelectionBottomSheetFragment = new FlairBottomSheetFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
flairSelectionBottomSheetFragment.setArguments(bundle);
|
||||
flairSelectionBottomSheetFragment.show(getSupportFragmentManager(), flairSelectionBottomSheetFragment.getTag());
|
||||
} else {
|
||||
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
flairTextView.setText(getString(R.string.flair));
|
||||
flair = null;
|
||||
}
|
||||
});
|
||||
|
||||
spoilerTextView.setOnClickListener(view -> {
|
||||
if (!isSpoiler) {
|
||||
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setBorderColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setTextColor(spoilerTextColor);
|
||||
isSpoiler = true;
|
||||
} else {
|
||||
spoilerTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
spoilerTextView.setTextColor(primaryTextColor);
|
||||
isSpoiler = false;
|
||||
}
|
||||
});
|
||||
|
||||
nsfwTextView.setOnClickListener(view -> {
|
||||
if (!isNSFW) {
|
||||
@@ -426,8 +401,6 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
spoilerTextColor = mCustomThemeWrapper.getSpoilerTextColor();
|
||||
nsfwBackgroundColor = mCustomThemeWrapper.getNsfwBackgroundColor();
|
||||
nsfwTextColor = mCustomThemeWrapper.getNsfwTextColor();
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
spoilerTextView.setTextColor(primaryTextColor);
|
||||
nsfwTextView.setTextColor(primaryTextColor);
|
||||
titleEditText.setTextColor(primaryTextColor);
|
||||
titleEditText.setHintTextColor(secondaryTextColor);
|
||||
@@ -439,8 +412,6 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
subredditNameTextView.setTypeface(typeface);
|
||||
rulesButton.setTypeface(typeface);
|
||||
receivePostReplyNotificationsTextView.setTypeface(typeface);
|
||||
flairTextView.setTypeface(typeface);
|
||||
spoilerTextView.setTypeface(typeface);
|
||||
nsfwTextView.setTypeface(typeface);
|
||||
titleEditText.setTypeface(typeface);
|
||||
suggestTitleButton.setTypeface(typeface);
|
||||
@@ -541,7 +512,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
|
||||
Intent intent = new Intent(this, SubmitPostService.class);
|
||||
intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, communityData.getId());
|
||||
intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
|
||||
intent.putExtra(SubmitPostService.EXTRA_CONTENT, linkEditText.getText().toString());
|
||||
intent.putExtra(SubmitPostService.EXTRA_KIND, APIUtils.KIND_LINK);
|
||||
@@ -575,6 +546,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelable(SELECTED_ACCOUNT_STATE, selectedAccount);
|
||||
outState.putParcelable(COMMUNITY_DATA_STATE, communityData);
|
||||
outState.putString(SUBREDDIT_NAME_STATE, subredditName);
|
||||
outState.putString(SUBREDDIT_ICON_STATE, iconUrl);
|
||||
outState.putBoolean(SUBREDDIT_SELECTED_STATE, subredditSelected);
|
||||
@@ -591,19 +563,16 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
subredditName = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
iconUrl = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);
|
||||
communityData = data.getExtras().getParcelable(SubredditSelectionActivity.EXTRA_RETURN_COMMUNITY_DATA);
|
||||
subredditName = communityData.getName();
|
||||
iconUrl = communityData.getIconUrl();
|
||||
subredditSelected = true;
|
||||
subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER);
|
||||
subredditIsUser = false;
|
||||
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
displaySubredditIcon();
|
||||
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
flairTextView.setText(getString(R.string.flair));
|
||||
flair = null;
|
||||
}
|
||||
}
|
||||
@@ -618,10 +587,6 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
@Override
|
||||
public void flairSelected(Flair flair) {
|
||||
this.flair = flair;
|
||||
flairTextView.setText(flair.getText());
|
||||
flairTextView.setBackgroundColor(flairBackgroundColor);
|
||||
flairTextView.setBorderColor(flairBackgroundColor);
|
||||
flairTextView.setTextColor(flairTextColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,7 +12,6 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
@@ -64,6 +63,9 @@ import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.events.SubmitPollPostEvent;
|
||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.services.SubmitPostService;
|
||||
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||
@@ -87,6 +89,7 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
private static final String IS_NSFW_STATE = "INS";
|
||||
|
||||
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
||||
private static final String COMMUNITY_DATA_STATE = "CDS";
|
||||
|
||||
@BindView(R.id.coordinator_layout_post_poll_activity)
|
||||
CoordinatorLayout coordinatorLayout;
|
||||
@@ -108,10 +111,6 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
MaterialButton rulesButton;
|
||||
@BindView(R.id.divider_1_post_poll_activity)
|
||||
MaterialDivider divider1;
|
||||
@BindView(R.id.flair_custom_text_view_post_poll_activity)
|
||||
CustomTextView flairTextView;
|
||||
@BindView(R.id.spoiler_custom_text_view_post_poll_activity)
|
||||
CustomTextView spoilerTextView;
|
||||
@BindView(R.id.nsfw_custom_text_view_post_poll_activity)
|
||||
CustomTextView nsfwTextView;
|
||||
@BindView(R.id.receive_post_reply_notifications_linear_layout_post_poll_activity)
|
||||
@@ -173,6 +172,7 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
@Inject
|
||||
Executor mExecutor;
|
||||
private Account selectedAccount;
|
||||
private SubscribedSubredditData communityData;
|
||||
private String mAccessToken;
|
||||
private String mAccountName;
|
||||
private String iconUrl;
|
||||
@@ -232,6 +232,7 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
selectedAccount = savedInstanceState.getParcelable(SELECTED_ACCOUNT_STATE);
|
||||
communityData = savedInstanceState.getParcelable(COMMUNITY_DATA_STATE);
|
||||
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
||||
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
|
||||
subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
|
||||
@@ -257,7 +258,6 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
if (subredditName != null) {
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
if (!loadSubredditIconSuccessful) {
|
||||
loadSubredditIcon();
|
||||
}
|
||||
@@ -268,17 +268,6 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
mPostingSnackbar.show();
|
||||
}
|
||||
|
||||
if (flair != null) {
|
||||
flairTextView.setText(flair.getText());
|
||||
flairTextView.setBackgroundColor(flairBackgroundColor);
|
||||
flairTextView.setBorderColor(flairBackgroundColor);
|
||||
flairTextView.setTextColor(flairTextColor);
|
||||
}
|
||||
if (isSpoiler) {
|
||||
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setBorderColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setTextColor(spoilerTextColor);
|
||||
}
|
||||
if (isNSFW) {
|
||||
nsfwTextView.setBackgroundColor(nsfwBackgroundColor);
|
||||
nsfwTextView.setBorderColor(nsfwBackgroundColor);
|
||||
@@ -292,11 +281,25 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
||||
loadSubredditIconSuccessful = false;
|
||||
subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
|
||||
subredditSelected = true;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
loadSubredditIcon();
|
||||
FetchSubredditData.fetchSubredditData(mRetrofit.getRetrofit(), subredditName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
{
|
||||
communityData = new SubscribedSubredditData(subredditData);
|
||||
subredditName = communityData.getName();
|
||||
subredditIsUser = false;
|
||||
subredditSelected = true;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
loadSubredditIcon();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchSubredditDataFail(boolean isQuarantined) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mGlide.load(R.drawable.subreddit_default_icon)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||
@@ -325,40 +328,12 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
if (subredditIsUser) {
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, "u_" + subredditName);
|
||||
} else {
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, communityData.getQualified_name());
|
||||
}
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
flairTextView.setOnClickListener(view -> {
|
||||
if (flair == null) {
|
||||
flairSelectionBottomSheetFragment = new FlairBottomSheetFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
flairSelectionBottomSheetFragment.setArguments(bundle);
|
||||
flairSelectionBottomSheetFragment.show(getSupportFragmentManager(), flairSelectionBottomSheetFragment.getTag());
|
||||
} else {
|
||||
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
flairTextView.setText(getString(R.string.flair));
|
||||
flair = null;
|
||||
}
|
||||
});
|
||||
|
||||
spoilerTextView.setOnClickListener(view -> {
|
||||
if (!isSpoiler) {
|
||||
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setBorderColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setTextColor(spoilerTextColor);
|
||||
isSpoiler = true;
|
||||
} else {
|
||||
spoilerTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
spoilerTextView.setTextColor(primaryTextColor);
|
||||
isSpoiler = false;
|
||||
}
|
||||
});
|
||||
|
||||
nsfwTextView.setOnClickListener(view -> {
|
||||
if (!isNSFW) {
|
||||
@@ -431,8 +406,6 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
spoilerTextColor = mCustomThemeWrapper.getSpoilerTextColor();
|
||||
nsfwBackgroundColor = mCustomThemeWrapper.getNsfwBackgroundColor();
|
||||
nsfwTextColor = mCustomThemeWrapper.getNsfwTextColor();
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
spoilerTextView.setTextColor(primaryTextColor);
|
||||
nsfwTextView.setTextColor(primaryTextColor);
|
||||
titleEditText.setTextColor(primaryTextColor);
|
||||
titleEditText.setHintTextColor(secondaryTextColor);
|
||||
@@ -481,8 +454,6 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
subredditNameTextView.setTypeface(typeface);
|
||||
rulesButton.setTypeface(typeface);
|
||||
receivePostReplyNotificationsTextView.setTypeface(typeface);
|
||||
flairTextView.setTypeface(typeface);
|
||||
spoilerTextView.setTypeface(typeface);
|
||||
nsfwTextView.setTypeface(typeface);
|
||||
titleEditText.setTypeface(typeface);
|
||||
option1TextInputEditText.setTypeface(typeface);
|
||||
@@ -631,7 +602,7 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
|
||||
Intent intent = new Intent(this, SubmitPostService.class);
|
||||
intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, communityData.getId());
|
||||
intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_POLL);
|
||||
PollPayload payload = new PollPayload(subredditName, titleEditText.getText().toString(),
|
||||
optionList.toArray(new String[0]), (int) votingLengthSlider.getValue(), isNSFW, isSpoiler, flair, receivePostReplyNotificationsSwitchMaterial.isChecked(),
|
||||
@@ -669,6 +640,7 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelable(SELECTED_ACCOUNT_STATE, selectedAccount);
|
||||
outState.putParcelable(COMMUNITY_DATA_STATE, communityData);
|
||||
outState.putString(SUBREDDIT_NAME_STATE, subredditName);
|
||||
outState.putString(SUBREDDIT_ICON_STATE, iconUrl);
|
||||
outState.putBoolean(SUBREDDIT_SELECTED_STATE, subredditSelected);
|
||||
@@ -685,19 +657,16 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
subredditName = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
iconUrl = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);
|
||||
communityData = data.getParcelableExtra(SubredditSelectionActivity.EXTRA_RETURN_COMMUNITY_DATA);
|
||||
subredditName = communityData.getName();
|
||||
iconUrl = communityData.getIconUrl();
|
||||
subredditSelected = true;
|
||||
subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER);
|
||||
subredditIsUser = false;
|
||||
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
displaySubredditIcon();
|
||||
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
flairTextView.setText(getString(R.string.flair));
|
||||
flair = null;
|
||||
}
|
||||
}
|
||||
@@ -706,10 +675,6 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
@Override
|
||||
public void flairSelected(Flair flair) {
|
||||
this.flair = flair;
|
||||
flairTextView.setText(flair.getText());
|
||||
flairTextView.setBackgroundColor(flairBackgroundColor);
|
||||
flairTextView.setBorderColor(flairBackgroundColor);
|
||||
flairTextView.setTextColor(flairTextColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,7 +12,6 @@ import android.os.Handler;
|
||||
import android.provider.MediaStore;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
@@ -69,6 +68,9 @@ import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
|
||||
import eu.toldi.infinityforlemmy.events.SubmitTextOrLinkPostEvent;
|
||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.services.SubmitPostService;
|
||||
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
@@ -78,7 +80,6 @@ import retrofit2.Retrofit;
|
||||
|
||||
public class PostTextActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback,
|
||||
UploadImageEnabledActivity, AccountChooserBottomSheetFragment.AccountChooserListener {
|
||||
|
||||
static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
||||
static final String EXTRA_CONTENT = "EC";
|
||||
|
||||
@@ -98,6 +99,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
private static final int PICK_IMAGE_REQUEST_CODE = 100;
|
||||
private static final int CAPTURE_IMAGE_REQUEST_CODE = 200;
|
||||
private static final int MARKDOWN_PREVIEW_REQUEST_CODE = 300;
|
||||
private static final String COMMUNITY_DATA_STATE = "CDS";
|
||||
|
||||
@BindView(R.id.coordinator_layout_post_text_activity)
|
||||
CoordinatorLayout coordinatorLayout;
|
||||
@@ -119,10 +121,6 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
MaterialButton rulesButton;
|
||||
@BindView(R.id.divider_1_post_text_activity)
|
||||
MaterialDivider divider1;
|
||||
@BindView(R.id.flair_custom_text_view_post_text_activity)
|
||||
CustomTextView flairTextView;
|
||||
@BindView(R.id.spoiler_custom_text_view_post_text_activity)
|
||||
CustomTextView spoilerTextView;
|
||||
@BindView(R.id.nsfw_custom_text_view_post_text_activity)
|
||||
CustomTextView nsfwTextView;
|
||||
@BindView(R.id.receive_post_reply_notifications_linear_layout_post_text_activity)
|
||||
@@ -164,6 +162,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
private String mAccessToken;
|
||||
private String iconUrl;
|
||||
private String subredditName;
|
||||
private SubscribedSubredditData communityData;
|
||||
private boolean subredditSelected = false;
|
||||
private boolean subredditIsUser;
|
||||
private boolean loadSubredditIconSuccessful = true;
|
||||
@@ -219,6 +218,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
selectedAccount = savedInstanceState.getParcelable(SELECTED_ACCOUNT_STATE);
|
||||
communityData = savedInstanceState.getParcelable(COMMUNITY_DATA_STATE);
|
||||
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
||||
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
|
||||
subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE);
|
||||
@@ -245,7 +245,6 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
if (subredditName != null) {
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
if (!loadSubredditIconSuccessful) {
|
||||
loadSubredditIcon();
|
||||
}
|
||||
@@ -256,17 +255,6 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
mPostingSnackbar.show();
|
||||
}
|
||||
|
||||
if (flair != null) {
|
||||
flairTextView.setText(flair.getText());
|
||||
flairTextView.setBackgroundColor(flairBackgroundColor);
|
||||
flairTextView.setBorderColor(flairBackgroundColor);
|
||||
flairTextView.setTextColor(flairTextColor);
|
||||
}
|
||||
if (isSpoiler) {
|
||||
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setBorderColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setTextColor(spoilerTextColor);
|
||||
}
|
||||
if (isNSFW) {
|
||||
nsfwTextView.setBackgroundColor(nsfwBackgroundColor);
|
||||
nsfwTextView.setBorderColor(nsfwBackgroundColor);
|
||||
@@ -280,11 +268,25 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
||||
loadSubredditIconSuccessful = false;
|
||||
subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
|
||||
subredditSelected = true;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
loadSubredditIcon();
|
||||
FetchSubredditData.fetchSubredditData(mRetrofit.getRetrofit(), subredditName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
{
|
||||
communityData = new SubscribedSubredditData(subredditData);
|
||||
subredditName = communityData.getName();
|
||||
subredditIsUser = false;
|
||||
subredditSelected = true;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
loadSubredditIcon();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchSubredditDataFail(boolean isQuarantined) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mGlide.load(R.drawable.subreddit_default_icon)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||
@@ -318,44 +320,12 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
if (subredditIsUser) {
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, "u_" + subredditName);
|
||||
} else {
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, communityData.getQualified_name());
|
||||
}
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
flairTextView.setOnClickListener(view -> {
|
||||
if (flair == null) {
|
||||
flairSelectionBottomSheetFragment = new FlairBottomSheetFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
if (subredditIsUser) {
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_SUBREDDIT_NAME, "u_" + subredditName);
|
||||
} else {
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
}
|
||||
flairSelectionBottomSheetFragment.setArguments(bundle);
|
||||
flairSelectionBottomSheetFragment.show(getSupportFragmentManager(), flairSelectionBottomSheetFragment.getTag());
|
||||
} else {
|
||||
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
flairTextView.setText(getString(R.string.flair));
|
||||
flair = null;
|
||||
}
|
||||
});
|
||||
|
||||
spoilerTextView.setOnClickListener(view -> {
|
||||
if (!isSpoiler) {
|
||||
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setBorderColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setTextColor(spoilerTextColor);
|
||||
isSpoiler = true;
|
||||
} else {
|
||||
spoilerTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
spoilerTextView.setTextColor(primaryTextColor);
|
||||
isSpoiler = false;
|
||||
}
|
||||
});
|
||||
|
||||
nsfwTextView.setOnClickListener(view -> {
|
||||
if (!isNSFW) {
|
||||
@@ -448,8 +418,6 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
spoilerTextColor = mCustomThemeWrapper.getSpoilerTextColor();
|
||||
nsfwBackgroundColor = mCustomThemeWrapper.getNsfwBackgroundColor();
|
||||
nsfwTextColor = mCustomThemeWrapper.getNsfwTextColor();
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
spoilerTextView.setTextColor(primaryTextColor);
|
||||
nsfwTextView.setTextColor(primaryTextColor);
|
||||
titleEditText.setTextColor(primaryTextColor);
|
||||
titleEditText.setHintTextColor(secondaryTextColor);
|
||||
@@ -459,8 +427,6 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
subredditNameTextView.setTypeface(typeface);
|
||||
rulesButton.setTypeface(typeface);
|
||||
receivePostReplyNotificationsTextView.setTypeface(typeface);
|
||||
flairTextView.setTypeface(typeface);
|
||||
spoilerTextView.setTypeface(typeface);
|
||||
nsfwTextView.setTypeface(typeface);
|
||||
titleEditText.setTypeface(typeface);
|
||||
}
|
||||
@@ -562,16 +528,10 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
|
||||
mPostingSnackbar.show();
|
||||
|
||||
String subredditName;
|
||||
if (subredditIsUser) {
|
||||
subredditName = "u_" + subredditNameTextView.getText().toString();
|
||||
} else {
|
||||
subredditName = subredditNameTextView.getText().toString();
|
||||
}
|
||||
|
||||
Intent intent = new Intent(this, SubmitPostService.class);
|
||||
intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, communityData.getId());
|
||||
intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
|
||||
intent.putExtra(SubmitPostService.EXTRA_CONTENT, contentEditText.getText().toString());
|
||||
intent.putExtra(SubmitPostService.EXTRA_KIND, APIUtils.KIND_SELF);
|
||||
@@ -599,6 +559,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
@Override
|
||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelable(COMMUNITY_DATA_STATE, communityData);
|
||||
outState.putParcelable(SELECTED_ACCOUNT_STATE, selectedAccount);
|
||||
outState.putString(SUBREDDIT_NAME_STATE, subredditName);
|
||||
outState.putString(SUBREDDIT_ICON_STATE, iconUrl);
|
||||
@@ -617,19 +578,16 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (resultCode == RESULT_OK) {
|
||||
if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
|
||||
subredditName = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
iconUrl = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);
|
||||
communityData = data.getParcelableExtra(SubredditSelectionActivity.EXTRA_RETURN_COMMUNITY_DATA);
|
||||
subredditName = communityData.getName();
|
||||
iconUrl = communityData.getIconUrl();
|
||||
subredditSelected = true;
|
||||
subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER);
|
||||
subredditIsUser = false;
|
||||
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
displaySubredditIcon();
|
||||
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
flairTextView.setText(getString(R.string.flair));
|
||||
flair = null;
|
||||
|
||||
} else if (requestCode == PICK_IMAGE_REQUEST_CODE) {
|
||||
@@ -637,10 +595,10 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
Toast.makeText(PostTextActivity.this, R.string.error_getting_image, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
|
||||
Utils.uploadImageToReddit(this, mExecutor, mRetrofit,
|
||||
mAccessToken, contentEditText, coordinatorLayout, data.getData(), uploadedImages);
|
||||
} else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) {
|
||||
Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
|
||||
Utils.uploadImageToReddit(this, mExecutor, mRetrofit,
|
||||
mAccessToken, contentEditText, coordinatorLayout, capturedImageUri, uploadedImages);
|
||||
} else if (requestCode == MARKDOWN_PREVIEW_REQUEST_CODE) {
|
||||
submitPost(mMenu.findItem(R.id.action_send_post_text_activity));
|
||||
@@ -658,10 +616,6 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
@Override
|
||||
public void flairSelected(Flair flair) {
|
||||
this.flair = flair;
|
||||
flairTextView.setText(flair.getText());
|
||||
flairTextView.setBackgroundColor(flairBackgroundColor);
|
||||
flairTextView.setBorderColor(flairBackgroundColor);
|
||||
flairTextView.setTextColor(flairTextColor);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
||||
@@ -67,6 +67,9 @@ import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.events.SubmitVideoOrGifPostEvent;
|
||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.services.SubmitPostService;
|
||||
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||
import pl.droidsonroids.gif.GifImageView;
|
||||
@@ -92,6 +95,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
||||
private static final int PICK_VIDEO_REQUEST_CODE = 1;
|
||||
private static final int CAPTURE_VIDEO_REQUEST_CODE = 2;
|
||||
private static final String COMMUNITY_DATA_STATE = "CDS";
|
||||
|
||||
@BindView(R.id.coordinator_layout_post_video_activity)
|
||||
CoordinatorLayout coordinatorLayout;
|
||||
@@ -113,10 +117,6 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
MaterialButton rulesButton;
|
||||
@BindView(R.id.divider_1_post_video_activity)
|
||||
MaterialDivider divider1;
|
||||
@BindView(R.id.flair_custom_text_view_post_video_activity)
|
||||
CustomTextView flairTextView;
|
||||
@BindView(R.id.spoiler_custom_text_view_post_video_activity)
|
||||
CustomTextView spoilerTextView;
|
||||
@BindView(R.id.nsfw_custom_text_view_post_video_activity)
|
||||
CustomTextView nsfwTextView;
|
||||
@BindView(R.id.receive_post_reply_notifications_linear_layout_post_video_activity)
|
||||
@@ -168,6 +168,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
private String mAccountName;
|
||||
private String iconUrl;
|
||||
private String subredditName;
|
||||
private SubscribedSubredditData communityData;
|
||||
private boolean subredditSelected = false;
|
||||
private boolean subredditIsUser;
|
||||
private Uri videoUri;
|
||||
@@ -235,6 +236,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
communityData = savedInstanceState.getParcelable(COMMUNITY_DATA_STATE);
|
||||
selectedAccount = savedInstanceState.getParcelable(SELECTED_ACCOUNT_STATE);
|
||||
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
||||
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
|
||||
@@ -266,7 +268,6 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
if (subredditName != null) {
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
if (!loadSubredditIconSuccessful) {
|
||||
loadSubredditIcon();
|
||||
}
|
||||
@@ -277,17 +278,6 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
mPostingSnackbar.show();
|
||||
}
|
||||
|
||||
if (flair != null) {
|
||||
flairTextView.setText(flair.getText());
|
||||
flairTextView.setBackgroundColor(flairBackgroundColor);
|
||||
flairTextView.setBorderColor(flairBackgroundColor);
|
||||
flairTextView.setTextColor(flairTextColor);
|
||||
}
|
||||
if (isSpoiler) {
|
||||
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setBorderColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setTextColor(spoilerTextColor);
|
||||
}
|
||||
if (isNSFW) {
|
||||
nsfwTextView.setBackgroundColor(nsfwBackgroundColor);
|
||||
nsfwTextView.setBorderColor(nsfwBackgroundColor);
|
||||
@@ -301,11 +291,25 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
||||
loadSubredditIconSuccessful = false;
|
||||
subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
|
||||
subredditSelected = true;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
loadSubredditIcon();
|
||||
FetchSubredditData.fetchSubredditData(mRetrofit.getRetrofit(), subredditName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
{
|
||||
communityData = new SubscribedSubredditData(subredditData);
|
||||
subredditName = communityData.getName();
|
||||
subredditIsUser = false;
|
||||
subredditSelected = true;
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
loadSubredditIcon();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchSubredditDataFail(boolean isQuarantined) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mGlide.load(R.drawable.subreddit_default_icon)
|
||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||
@@ -341,40 +345,12 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
if (subredditIsUser) {
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, "u_" + subredditName);
|
||||
} else {
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(RulesActivity.EXTRA_SUBREDDIT_NAME, communityData.getQualified_name());
|
||||
}
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
flairTextView.setOnClickListener(view -> {
|
||||
if (flair == null) {
|
||||
mFlairSelectionBottomSheetFragment = new FlairBottomSheetFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
mFlairSelectionBottomSheetFragment.setArguments(bundle);
|
||||
mFlairSelectionBottomSheetFragment.show(getSupportFragmentManager(), mFlairSelectionBottomSheetFragment.getTag());
|
||||
} else {
|
||||
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
flairTextView.setText(getString(R.string.flair));
|
||||
flair = null;
|
||||
}
|
||||
});
|
||||
|
||||
spoilerTextView.setOnClickListener(view -> {
|
||||
if (!isSpoiler) {
|
||||
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setBorderColor(spoilerBackgroundColor);
|
||||
spoilerTextView.setTextColor(spoilerTextColor);
|
||||
isSpoiler = true;
|
||||
} else {
|
||||
spoilerTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
spoilerTextView.setTextColor(primaryTextColor);
|
||||
isSpoiler = false;
|
||||
}
|
||||
});
|
||||
|
||||
nsfwTextView.setOnClickListener(view -> {
|
||||
if (!isNSFW) {
|
||||
@@ -468,8 +444,6 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
spoilerTextColor = mCustomThemeWrapper.getSpoilerTextColor();
|
||||
nsfwBackgroundColor = mCustomThemeWrapper.getNsfwBackgroundColor();
|
||||
nsfwTextColor = mCustomThemeWrapper.getNsfwTextColor();
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
spoilerTextView.setTextColor(primaryTextColor);
|
||||
nsfwTextView.setTextColor(primaryTextColor);
|
||||
titleEditText.setTextColor(primaryTextColor);
|
||||
titleEditText.setHintTextColor(secondaryTextColor);
|
||||
@@ -480,8 +454,6 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
subredditNameTextView.setTypeface(typeface);
|
||||
rulesButton.setTypeface(typeface);
|
||||
receivePostReplyNotificationsTextView.setTypeface(typeface);
|
||||
flairTextView.setTypeface(typeface);
|
||||
spoilerTextView.setTypeface(typeface);
|
||||
nsfwTextView.setTypeface(typeface);
|
||||
titleEditText.setTypeface(typeface);
|
||||
selectAgainTextView.setTypeface(typeface);
|
||||
@@ -589,7 +561,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
Intent intent = new Intent(this, SubmitPostService.class);
|
||||
intent.setData(videoUri);
|
||||
intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, communityData.getId());
|
||||
intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
|
||||
intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair);
|
||||
intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler);
|
||||
@@ -637,6 +609,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelable(SELECTED_ACCOUNT_STATE, selectedAccount);
|
||||
outState.putParcelable(COMMUNITY_DATA_STATE, communityData);
|
||||
outState.putString(SUBREDDIT_NAME_STATE, subredditName);
|
||||
outState.putString(SUBREDDIT_ICON_STATE, iconUrl);
|
||||
outState.putBoolean(SUBREDDIT_SELECTED_STATE, subredditSelected);
|
||||
@@ -657,19 +630,16 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
if (data != null) {
|
||||
subredditName = data.getStringExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
iconUrl = data.getStringExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);
|
||||
communityData = data.getParcelableExtra(SubredditSelectionActivity.EXTRA_RETURN_COMMUNITY_DATA);
|
||||
subredditName = communityData.getName();
|
||||
iconUrl = communityData.getIconUrl();
|
||||
subredditSelected = true;
|
||||
subredditIsUser = data.getBooleanExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER, false);
|
||||
subredditIsUser = false;
|
||||
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
displaySubredditIcon();
|
||||
|
||||
flairTextView.setVisibility(View.VISIBLE);
|
||||
flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
|
||||
flairTextView.setTextColor(primaryTextColor);
|
||||
flairTextView.setText(getString(R.string.flair));
|
||||
flair = null;
|
||||
}
|
||||
}
|
||||
@@ -707,10 +677,6 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
@Override
|
||||
public void flairSelected(Flair flair) {
|
||||
this.flair = flair;
|
||||
flairTextView.setText(flair.getText());
|
||||
flairTextView.setBackgroundColor(flairBackgroundColor);
|
||||
flairTextView.setBorderColor(flairBackgroundColor);
|
||||
flairTextView.setTextColor(flairTextColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.content.SharedPreferences;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
@@ -31,7 +30,6 @@ import javax.inject.Named;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.toldi.infinityforlemmy.FetchRules;
|
||||
import eu.toldi.infinityforlemmy.Infinity;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
@@ -41,6 +39,8 @@ import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
|
||||
import eu.toldi.infinityforlemmy.customviews.slidr.widget.SliderPanel;
|
||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
@@ -134,26 +134,27 @@ public class RulesActivity extends BaseActivity {
|
||||
|
||||
mAdapter = new RulesRecyclerViewAdapter(this, mCustomThemeWrapper, sliderPanel);
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
|
||||
FetchRules.fetchRules(mExecutor, new Handler(), mAccessToken == null ? mRetrofit.getRetrofit() : mOauthRetrofit, mAccessToken, mSubredditName, new FetchRules.FetchRulesListener() {
|
||||
FetchSubredditData.fetchSubredditData(mRetrofit.getRetrofit(), mSubredditName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void success(ArrayList<Rule> rules) {
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
if (rules == null || rules.size() == 0) {
|
||||
String description = subredditData.getDescription();
|
||||
if (description == null || description.isEmpty()) {
|
||||
errorTextView.setVisibility(View.VISIBLE);
|
||||
errorTextView.setText(R.string.no_rule);
|
||||
errorTextView.setOnClickListener(view -> {
|
||||
});
|
||||
}
|
||||
ArrayList<Rule> rules = new ArrayList<>();
|
||||
rules.add(new Rule("Rules", description));
|
||||
mAdapter.changeDataset(rules);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed() {
|
||||
public void onFetchSubredditDataFail(boolean isQuarantined) {
|
||||
displayError();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -184,21 +185,24 @@ public class RulesActivity extends BaseActivity {
|
||||
errorTextView.setOnClickListener(view -> {
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
errorTextView.setVisibility(View.GONE);
|
||||
FetchRules.fetchRules(mExecutor, new Handler(), mAccessToken == null ? mRetrofit.getRetrofit() : mOauthRetrofit, mAccessToken, mSubredditName, new FetchRules.FetchRulesListener() {
|
||||
FetchSubredditData.fetchSubredditData(mRetrofit.getRetrofit(), mSubredditName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void success(ArrayList<Rule> rules) {
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
if (rules == null || rules.size() == 0) {
|
||||
String description = subredditData.getDescription();
|
||||
if (description == null || description.isEmpty()) {
|
||||
errorTextView.setVisibility(View.VISIBLE);
|
||||
errorTextView.setText(R.string.no_rule);
|
||||
errorTextView.setOnClickListener(view -> {
|
||||
});
|
||||
}
|
||||
ArrayList<Rule> rules = new ArrayList<>();
|
||||
rules.add(new Rule("Rules", description));
|
||||
mAdapter.changeDataset(rules);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed() {
|
||||
public void onFetchSubredditDataFail(boolean isQuarantined) {
|
||||
displayError();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -52,6 +52,7 @@ import eu.toldi.infinityforlemmy.recentsearchquery.RecentSearchQuery;
|
||||
import eu.toldi.infinityforlemmy.recentsearchquery.RecentSearchQueryViewModel;
|
||||
import eu.toldi.infinityforlemmy.subreddit.ParseSubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
@@ -128,6 +129,8 @@ public class SearchActivity extends BaseActivity {
|
||||
private String query;
|
||||
private String subredditName;
|
||||
|
||||
private SubscribedSubredditData communityData;
|
||||
|
||||
private String communityQualifiedName;
|
||||
private boolean subredditIsUser;
|
||||
private boolean searchOnlySubreddits;
|
||||
@@ -183,7 +186,7 @@ public class SearchActivity extends BaseActivity {
|
||||
subredditNameList.add(subredditData.getName());
|
||||
returnIntent.putStringArrayListExtra(RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES, subredditNameList);
|
||||
} else {
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME, subredditData.getName());
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME, new SubscribedSubredditData(subredditData));
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_ICON_URL, subredditData.getIconUrl());
|
||||
}
|
||||
setResult(Activity.RESULT_OK, returnIntent);
|
||||
@@ -429,8 +432,9 @@ public class SearchActivity extends BaseActivity {
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
if (resultCode == RESULT_OK && data != null) {
|
||||
if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
|
||||
subredditName = data.getStringExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
subredditIsUser = data.getBooleanExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER, false);
|
||||
communityData = data.getParcelableExtra(SubredditSelectionActivity.EXTRA_RETURN_COMMUNITY_DATA);
|
||||
subredditName = communityData.getName();
|
||||
subredditIsUser = false;
|
||||
|
||||
if (subredditName == null) {
|
||||
subredditNameTextView.setText(R.string.all_communities);
|
||||
@@ -442,9 +446,9 @@ public class SearchActivity extends BaseActivity {
|
||||
if (getIntent().getBooleanExtra(EXTRA_IS_MULTI_SELECTION, false)) {
|
||||
returnIntent.putStringArrayListExtra(RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES, data.getStringArrayListExtra(SearchSubredditsResultActivity.RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES));
|
||||
} else {
|
||||
String name = data.getStringExtra(SearchSubredditsResultActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
SubscribedSubredditData communityData = data.getParcelableExtra(SearchSubredditsResultActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
String iconUrl = data.getStringExtra(SearchSubredditsResultActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME, name);
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME, communityData);
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_ICON_URL, iconUrl);
|
||||
}
|
||||
setResult(Activity.RESULT_OK, returnIntent);
|
||||
|
||||
@@ -788,7 +788,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
||||
bundle.putString(SubredditListingFragment.EXTRA_QUERY, mQuery);
|
||||
bundle.putBoolean(SubredditListingFragment.EXTRA_IS_GETTING_SUBREDDIT_INFO, false);
|
||||
bundle.putString(SubredditListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(SubredditListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||
bundle.putString(SubredditListingFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
|
||||
mFragment.setArguments(bundle);
|
||||
return mFragment;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
|
||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.fragments.SubredditListingFragment;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
|
||||
public class SearchSubredditsResultActivity extends BaseActivity implements ActivityToolbarInterface {
|
||||
@@ -64,6 +66,8 @@ public class SearchSubredditsResultActivity extends BaseActivity implements Acti
|
||||
private String mAccessToken;
|
||||
private String mAccountName;
|
||||
|
||||
private String mAccountQualifiedName;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
((Infinity) getApplication()).getAppComponent().inject(this);
|
||||
@@ -107,6 +111,7 @@ public class SearchSubredditsResultActivity extends BaseActivity implements Acti
|
||||
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||
mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
mFragment = new SubredditListingFragment();
|
||||
@@ -114,7 +119,7 @@ public class SearchSubredditsResultActivity extends BaseActivity implements Acti
|
||||
bundle.putString(SubredditListingFragment.EXTRA_QUERY, query);
|
||||
bundle.putBoolean(SubredditListingFragment.EXTRA_IS_GETTING_SUBREDDIT_INFO, true);
|
||||
bundle.putString(SubredditListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(SubredditListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||
bundle.putString(SubredditListingFragment.EXTRA_ACCOUNT_NAME, mAccountQualifiedName);
|
||||
bundle.putBoolean(SubredditListingFragment.EXTRA_IS_MULTI_SELECTION, getIntent().getBooleanExtra(EXTRA_IS_MULTI_SELECTION, false));
|
||||
mFragment.setArguments(bundle);
|
||||
} else {
|
||||
@@ -141,10 +146,10 @@ public class SearchSubredditsResultActivity extends BaseActivity implements Acti
|
||||
applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar);
|
||||
}
|
||||
|
||||
public void getSelectedSubreddit(String name, String iconUrl) {
|
||||
public void getSelectedSubreddit(SubredditData subredditData) {
|
||||
Intent returnIntent = new Intent();
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME, name);
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_ICON_URL, iconUrl);
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME, new SubscribedSubredditData(subredditData));
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_ICON_URL, subredditData.getIconUrl());
|
||||
setResult(Activity.RESULT_OK, returnIntent);
|
||||
finish();
|
||||
}
|
||||
|
||||
@@ -64,6 +64,7 @@ import eu.toldi.infinityforlemmy.events.SubmitCrosspostEvent;
|
||||
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.post.Post;
|
||||
import eu.toldi.infinityforlemmy.services.SubmitPostService;
|
||||
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||
@@ -87,6 +88,7 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
|
||||
private static final String IS_NSFW_STATE = "INS";
|
||||
|
||||
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
||||
private static final String COMMUNITY_DATA_STATE = "CDS";
|
||||
|
||||
@BindView(R.id.coordinator_layout_submit_crosspost_activity)
|
||||
CoordinatorLayout coordinatorLayout;
|
||||
@@ -159,6 +161,7 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
|
||||
private Post post;
|
||||
private String iconUrl;
|
||||
private String subredditName;
|
||||
private SubscribedSubredditData communityData;
|
||||
private boolean subredditSelected = false;
|
||||
private boolean subredditIsUser;
|
||||
private boolean loadSubredditIconSuccessful = true;
|
||||
@@ -212,6 +215,7 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
communityData = savedInstanceState.getParcelable(COMMUNITY_DATA_STATE);
|
||||
selectedAccount = savedInstanceState.getParcelable(SELECTED_ACCOUNT_STATE);
|
||||
subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE);
|
||||
iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE);
|
||||
@@ -566,7 +570,7 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
|
||||
|
||||
Intent intent = new Intent(this, SubmitPostService.class);
|
||||
intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, communityData.getId());
|
||||
intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
|
||||
if (post.isCrosspost()) {
|
||||
intent.putExtra(SubmitPostService.EXTRA_CONTENT, "t3_" + post.getCrosspostParentId());
|
||||
@@ -604,6 +608,7 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
|
||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelable(SELECTED_ACCOUNT_STATE, selectedAccount);
|
||||
outState.putParcelable(COMMUNITY_DATA_STATE, communityData);
|
||||
outState.putString(SUBREDDIT_NAME_STATE, subredditName);
|
||||
outState.putString(SUBREDDIT_ICON_STATE, iconUrl);
|
||||
outState.putBoolean(SUBREDDIT_SELECTED_STATE, subredditSelected);
|
||||
@@ -620,10 +625,11 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
subredditName = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
iconUrl = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);
|
||||
communityData = data.getParcelableExtra(SubredditSelectionActivity.EXTRA_RETURN_COMMUNITY_DATA);
|
||||
subredditName = communityData.getName();
|
||||
iconUrl = communityData.getIconUrl();
|
||||
subredditSelected = true;
|
||||
subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER);
|
||||
subredditIsUser = false;
|
||||
|
||||
subredditNameTextView.setTextColor(primaryTextColor);
|
||||
subredditNameTextView.setText(subredditName);
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
@@ -33,7 +32,6 @@ import javax.inject.Named;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.toldi.infinityforlemmy.ActivityToolbarInterface;
|
||||
import eu.toldi.infinityforlemmy.AnyAccountAccessTokenAuthenticator;
|
||||
import eu.toldi.infinityforlemmy.FetchSubscribedThing;
|
||||
import eu.toldi.infinityforlemmy.Infinity;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
@@ -49,17 +47,12 @@ import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
|
||||
import eu.toldi.infinityforlemmy.subscribeduser.SubscribedUserData;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import okhttp3.ConnectionPool;
|
||||
import okhttp3.OkHttpClient;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class SubredditSelectionActivity extends BaseActivity implements ActivityToolbarInterface {
|
||||
|
||||
public static final String EXTRA_SPECIFIED_ACCOUNT = "ESA";
|
||||
public static final String EXTRA_EXTRA_CLEAR_SELECTION = "EECS";
|
||||
public static final String EXTRA_RETURN_SUBREDDIT_NAME = "ERSN";
|
||||
public static final String EXTRA_RETURN_SUBREDDIT_ICON_URL = "ERSIURL";
|
||||
public static final String EXTRA_RETURN_SUBREDDIT_IS_USER = "ERSIU";
|
||||
public static final String EXTRA_RETURN_COMMUNITY_DATA = "ERCD";
|
||||
|
||||
private static final int SUBREDDIT_SEARCH_REQUEST_CODE = 0;
|
||||
private static final String INSERT_SUBSCRIBED_SUBREDDIT_STATE = "ISSS";
|
||||
@@ -77,9 +70,6 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity
|
||||
@Named("no_oauth")
|
||||
RetrofitHolder mRetrofit;
|
||||
@Inject
|
||||
@Named("oauth")
|
||||
Retrofit mOauthRetrofit;
|
||||
@Inject
|
||||
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||
@Inject
|
||||
@Named("default")
|
||||
@@ -142,21 +132,14 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity
|
||||
mAccountName = specifiedAccount.getAccountName();
|
||||
mAccountProfileImageUrl = specifiedAccount.getProfileImageUrl();
|
||||
|
||||
mOauthRetrofit = mOauthRetrofit.newBuilder().client(new OkHttpClient.Builder().authenticator(new AnyAccountAccessTokenAuthenticator(mRetrofit.getRetrofit(), mRedditDataRoomDatabase, specifiedAccount, mCurrentAccountSharedPreferences))
|
||||
.connectTimeout(30, TimeUnit.SECONDS)
|
||||
.readTimeout(30, TimeUnit.SECONDS)
|
||||
.writeTimeout(30, TimeUnit.SECONDS)
|
||||
.connectionPool(new ConnectionPool(0, 1, TimeUnit.NANOSECONDS))
|
||||
.build())
|
||||
.build();
|
||||
} else {
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
|
||||
mAccountProfileImageUrl = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_IMAGE_URL, null);
|
||||
}
|
||||
} else {
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
|
||||
mAccountProfileImageUrl = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_IMAGE_URL, null);
|
||||
}
|
||||
|
||||
@@ -198,6 +181,7 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity
|
||||
mFragment = new SubscribedSubredditsListingFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(SubscribedSubredditsListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||
bundle.putString(SubscribedSubredditsListingFragment.EXTRA_ACCOUNT_QUALIFIED_NAME, mAccountName);
|
||||
bundle.putString(SubscribedSubredditsListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(SubscribedSubredditsListingFragment.EXTRA_ACCOUNT_PROFILE_IMAGE_URL, mAccountProfileImageUrl);
|
||||
bundle.putBoolean(SubscribedSubredditsListingFragment.EXTRA_IS_SUBREDDIT_SELECTION, true);
|
||||
@@ -262,11 +246,9 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity
|
||||
return false;
|
||||
}
|
||||
|
||||
public void getSelectedSubreddit(String name, String iconUrl, boolean subredditIsUser) {
|
||||
public void getSelectedSubreddit(SubscribedSubredditData communityData) {
|
||||
Intent returnIntent = new Intent();
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME, name);
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_ICON_URL, iconUrl);
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_IS_USER, subredditIsUser);
|
||||
returnIntent.putExtra(EXTRA_RETURN_COMMUNITY_DATA, communityData);
|
||||
setResult(Activity.RESULT_OK, returnIntent);
|
||||
finish();
|
||||
}
|
||||
@@ -275,13 +257,13 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
if (requestCode == SUBREDDIT_SEARCH_REQUEST_CODE) {
|
||||
if (resultCode == RESULT_OK) {
|
||||
String name = data.getStringExtra(SearchActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
String iconUrl = data.getStringExtra(SearchActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);
|
||||
|
||||
SubscribedSubredditData communityData = data.getParcelableExtra(SearchActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
String iconUrl = communityData.getIconUrl();
|
||||
Intent returnIntent = new Intent();
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME, name);
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_ICON_URL, iconUrl);
|
||||
returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_IS_USER, false);
|
||||
returnIntent.putExtra(EXTRA_RETURN_COMMUNITY_DATA, communityData);
|
||||
setResult(Activity.RESULT_OK, returnIntent);
|
||||
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ import eu.toldi.infinityforlemmy.LoadingMorePostsStatus;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import eu.toldi.infinityforlemmy.SaveComment;
|
||||
import eu.toldi.infinityforlemmy.SaveThing;
|
||||
import eu.toldi.infinityforlemmy.SortType;
|
||||
import eu.toldi.infinityforlemmy.SortTypeSelectionCallback;
|
||||
@@ -443,9 +444,10 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
|
||||
}
|
||||
|
||||
public void saveComment(@NonNull Comment comment, int position) {
|
||||
SaveComment saveComment = new SaveComment();
|
||||
if (comment.isSaved()) {
|
||||
comment.setSaved(false);
|
||||
SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, comment.getFullName(), new SaveThing.SaveThingListener() {
|
||||
saveComment.unsaveThing(mOauthRetrofit, mAccessToken, comment.getId(), new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
ViewPostDetailFragment fragment = sectionsPagerAdapter.getCurrentFragment();
|
||||
@@ -466,7 +468,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
|
||||
});
|
||||
} else {
|
||||
comment.setSaved(true);
|
||||
SaveThing.saveThing(mOauthRetrofit, mAccessToken, comment.getFullName(), new SaveThing.SaveThingListener() {
|
||||
saveComment.saveThing(mRetrofit.getRetrofit(), mAccessToken, comment.getId(), new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
ViewPostDetailFragment fragment = sectionsPagerAdapter.getCurrentFragment();
|
||||
@@ -867,7 +869,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
|
||||
if (postListPosition == position && post != null) {
|
||||
bundle.putParcelable(ViewPostDetailFragment.EXTRA_POST_DATA, post);
|
||||
bundle.putInt(ViewPostDetailFragment.EXTRA_POST_LIST_POSITION, position);
|
||||
bundle.putString(ViewPostDetailFragment.EXTRA_SINGLE_COMMENT_ID, getIntent().getStringExtra(EXTRA_SINGLE_COMMENT_ID));
|
||||
bundle.putInt(ViewPostDetailFragment.EXTRA_SINGLE_COMMENT_ID, getIntent().getIntExtra(EXTRA_SINGLE_COMMENT_ID, 0));
|
||||
bundle.putString(ViewPostDetailFragment.EXTRA_CONTEXT_NUMBER, getIntent().getStringExtra(EXTRA_CONTEXT_NUMBER));
|
||||
bundle.putString(ViewPostDetailFragment.EXTRA_MESSAGE_FULLNAME, getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME));
|
||||
} else {
|
||||
@@ -883,12 +885,12 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
|
||||
}
|
||||
} else {
|
||||
if (post == null) {
|
||||
bundle.putString(ViewPostDetailFragment.EXTRA_POST_ID, getIntent().getStringExtra(EXTRA_POST_ID));
|
||||
bundle.putInt(ViewPostDetailFragment.EXTRA_POST_ID, getIntent().getIntExtra(EXTRA_POST_ID, 0));
|
||||
} else {
|
||||
bundle.putParcelable(ViewPostDetailFragment.EXTRA_POST_DATA, post);
|
||||
bundle.putInt(ViewPostDetailFragment.EXTRA_POST_LIST_POSITION, postListPosition);
|
||||
}
|
||||
bundle.putString(ViewPostDetailFragment.EXTRA_SINGLE_COMMENT_ID, getIntent().getStringExtra(EXTRA_SINGLE_COMMENT_ID));
|
||||
bundle.putInt(ViewPostDetailFragment.EXTRA_SINGLE_COMMENT_ID, getIntent().getIntExtra(EXTRA_SINGLE_COMMENT_ID, 0));
|
||||
bundle.putString(ViewPostDetailFragment.EXTRA_CONTEXT_NUMBER, getIntent().getStringExtra(EXTRA_CONTEXT_NUMBER));
|
||||
bundle.putString(ViewPostDetailFragment.EXTRA_MESSAGE_FULLNAME, getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME));
|
||||
}
|
||||
|
||||
@@ -96,10 +96,10 @@ import eu.toldi.infinityforlemmy.multireddit.MultiReddit;
|
||||
import eu.toldi.infinityforlemmy.post.Post;
|
||||
import eu.toldi.infinityforlemmy.post.PostPagingSource;
|
||||
import eu.toldi.infinityforlemmy.readpost.InsertReadPost;
|
||||
import eu.toldi.infinityforlemmy.subreddit.CommunitySubscription;
|
||||
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.ParseSubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditSubscription;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditViewModel;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
|
||||
@@ -116,7 +116,6 @@ import pl.droidsonroids.gif.GifImageView;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class ViewSubredditDetailActivity extends BaseActivity implements SortTypeSelectionCallback,
|
||||
PostTypeBottomSheetFragment.PostTypeSelectionCallback, PostLayoutBottomSheetFragment.PostLayoutSelectionCallback,
|
||||
@@ -174,9 +173,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
@Named("no_oauth")
|
||||
RetrofitHolder mRetrofit;
|
||||
@Inject
|
||||
@Named("oauth")
|
||||
Retrofit mOauthRetrofit;
|
||||
@Inject
|
||||
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||
@Inject
|
||||
@Named("default")
|
||||
@@ -207,7 +203,9 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
private String mAccessToken;
|
||||
private String mAccountName;
|
||||
private String mAccountQualifiedName;
|
||||
private String subredditName;
|
||||
private String communityName;
|
||||
|
||||
private int communityId;
|
||||
private String description;
|
||||
|
||||
private String qualifiedName;
|
||||
@@ -340,8 +338,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
lockBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_BOTTOM_APP_BAR, false);
|
||||
hideSubredditDescription = mSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_SUBREDDIT_DESCRIPTION, false);
|
||||
|
||||
subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME_KEY);
|
||||
qualifiedName = getIntent().getStringExtra(EXTRA_COMMUNITY_FULL_NAME_KEY);
|
||||
communityName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME_KEY);
|
||||
qualifiedName = getIntent().getStringExtra(EXTRA_COMMUNITY_FULL_NAME_KEY);
|
||||
|
||||
fragmentManager = getSupportFragmentManager();
|
||||
|
||||
@@ -366,7 +364,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
checkNewAccountAndBindView();
|
||||
|
||||
fetchSubredditData();
|
||||
if (subredditName != null) {
|
||||
if (communityName != null) {
|
||||
setupVisibleElements();
|
||||
}
|
||||
}
|
||||
@@ -457,10 +455,10 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
}
|
||||
|
||||
private void setupVisibleElements() {
|
||||
subredditNameTextView.setText(subredditName);
|
||||
subredditNameTextView.setText(communityName);
|
||||
communityFullNameTextView.setText(qualifiedName);
|
||||
|
||||
toolbar.setTitle(subredditName);
|
||||
toolbar.setTitle(communityName);
|
||||
setSupportActionBar(toolbar);
|
||||
setToolbarGoToTop(toolbar);
|
||||
|
||||
@@ -514,8 +512,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
bannerImageView.setOnClickListener(view -> {
|
||||
Intent intent = new Intent(ViewSubredditDetailActivity.this, ViewImageOrGifActivity.class);
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, subredditData.getBannerUrl());
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, subredditName + "-banner.jpg");
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, subredditName);
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, communityName + "-banner.jpg");
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, communityName);
|
||||
startActivity(intent);
|
||||
});
|
||||
}
|
||||
@@ -534,14 +532,14 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
iconGifImageView.setOnClickListener(view -> {
|
||||
Intent intent = new Intent(ViewSubredditDetailActivity.this, ViewImageOrGifActivity.class);
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, subredditData.getIconUrl());
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, subredditName + "-icon.jpg");
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, subredditName);
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, communityName + "-icon.jpg");
|
||||
intent.putExtra(ViewImageOrGifActivity.EXTRA_SUBREDDIT_OR_USERNAME_KEY, communityName);
|
||||
startActivity(intent);
|
||||
});
|
||||
}
|
||||
|
||||
String subredditFullName = subredditData.getTitle();
|
||||
if (!subredditName.equals(subredditFullName)) {
|
||||
if (!communityName.equals(subredditFullName)) {
|
||||
getSupportActionBar().setTitle(subredditFullName);
|
||||
}
|
||||
subredditNameTextView.setText(subredditFullName);
|
||||
@@ -577,21 +575,130 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
});
|
||||
}
|
||||
|
||||
private void setupSubscribeChip() {
|
||||
subscribeSubredditChip.setOnClickListener(view -> {
|
||||
if (mAccessToken == null) {
|
||||
if (subscriptionReady) {
|
||||
subscriptionReady = false;
|
||||
if (getResources().getString(R.string.subscribe).contentEquals(subscribeSubredditChip.getText())) {
|
||||
CommunitySubscription.anonymousSubscribeToSubreddit(mExecutor, new Handler(),
|
||||
mRetrofit.getRetrofit(), mRedditDataRoomDatabase, qualifiedName,
|
||||
new CommunitySubscription.SubredditSubscriptionListener() {
|
||||
@Override
|
||||
public void onSubredditSubscriptionSuccess() {
|
||||
subscribeSubredditChip.setText(R.string.unsubscribe);
|
||||
subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(subscribedColor));
|
||||
makeSnackbar(R.string.subscribed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubredditSubscriptionFail() {
|
||||
makeSnackbar(R.string.subscribe_failed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
CommunitySubscription.anonymousUnsubscribeToSubreddit(mExecutor, new Handler(),
|
||||
mRedditDataRoomDatabase, qualifiedName,
|
||||
new CommunitySubscription.SubredditSubscriptionListener() {
|
||||
@Override
|
||||
public void onSubredditSubscriptionSuccess() {
|
||||
subscribeSubredditChip.setText(R.string.subscribe);
|
||||
subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(unsubscribedColor));
|
||||
makeSnackbar(R.string.unsubscribed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubredditSubscriptionFail() {
|
||||
makeSnackbar(R.string.unsubscribe_failed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (subscriptionReady) {
|
||||
subscriptionReady = false;
|
||||
if (getResources().getString(R.string.subscribe).contentEquals(subscribeSubredditChip.getText())) {
|
||||
CommunitySubscription.subscribeToCommunity(mExecutor, new Handler(),
|
||||
mRetrofit.getRetrofit(), mAccessToken, communityId, qualifiedName, mAccountQualifiedName, mRedditDataRoomDatabase,
|
||||
new CommunitySubscription.SubredditSubscriptionListener() {
|
||||
@Override
|
||||
public void onSubredditSubscriptionSuccess() {
|
||||
subscribeSubredditChip.setText(R.string.unsubscribe);
|
||||
subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(subscribedColor));
|
||||
makeSnackbar(R.string.subscribed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubredditSubscriptionFail() {
|
||||
makeSnackbar(R.string.subscribe_failed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
CommunitySubscription.unsubscribeToCommunity(mExecutor, new Handler(),
|
||||
mRetrofit.getRetrofit(), mAccessToken, communityId, qualifiedName, mAccountName, mRedditDataRoomDatabase,
|
||||
new CommunitySubscription.SubredditSubscriptionListener() {
|
||||
@Override
|
||||
public void onSubredditSubscriptionSuccess() {
|
||||
subscribeSubredditChip.setText(R.string.subscribe);
|
||||
subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(unsubscribedColor));
|
||||
makeSnackbar(R.string.unsubscribed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubredditSubscriptionFail() {
|
||||
makeSnackbar(R.string.unsubscribe_failed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
CheckIsSubscribedToSubreddit.checkIsSubscribedToSubreddit(mExecutor, new Handler(),
|
||||
mRedditDataRoomDatabase, qualifiedName, mAccountQualifiedName,
|
||||
new CheckIsSubscribedToSubreddit.CheckIsSubscribedToSubredditListener() {
|
||||
@Override
|
||||
public void isSubscribed() {
|
||||
subscribeSubredditChip.setText(R.string.unsubscribe);
|
||||
subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(subscribedColor));
|
||||
subscriptionReady = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void isNotSubscribed() {
|
||||
subscribeSubredditChip.setText(R.string.subscribe);
|
||||
subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(unsubscribedColor));
|
||||
subscriptionReady = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void fetchSubredditData() {
|
||||
if (!mFetchSubredditInfoSuccess) {
|
||||
FetchSubredditData.fetchSubredditData(mOauthRetrofit, mRetrofit.getRetrofit(), qualifiedName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
FetchSubredditData.fetchSubredditData(mRetrofit.getRetrofit(), qualifiedName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
qualifiedName = LemmyUtils.actorID2FullName(subredditData.getActorId());
|
||||
if (subredditName == null) {
|
||||
subredditName = subredditData.getTitle();
|
||||
public void onFetchSubredditDataSuccess(SubredditData communityData, int nCurrentOnlineSubscribers) {
|
||||
qualifiedName = LemmyUtils.actorID2FullName(communityData.getActorId());
|
||||
if (communityName == null) {
|
||||
communityName = communityData.getTitle();
|
||||
|
||||
setupVisibleElements();
|
||||
}
|
||||
communityId = communityData.getId();
|
||||
setupSubscribeChip();
|
||||
|
||||
mNCurrentOnlineSubscribers = nCurrentOnlineSubscribers;
|
||||
nOnlineSubscribersTextView.setText(getString(R.string.online_subscribers_number_detail, nCurrentOnlineSubscribers));
|
||||
InsertSubredditData.insertSubredditData(mExecutor, new Handler(), mRedditDataRoomDatabase,
|
||||
subredditData, () -> mFetchSubredditInfoSuccess = true);
|
||||
communityData, () -> mFetchSubredditInfoSuccess = true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -648,7 +755,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
}
|
||||
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_OPTION_SEARCH: {
|
||||
Intent intent = new Intent(this, SearchActivity.class);
|
||||
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
@@ -762,7 +869,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
|
||||
private void bindView() {
|
||||
if (mMessageFullname != null) {
|
||||
ReadMessage.readMessage(mOauthRetrofit, mAccessToken, mMessageFullname, new ReadMessage.ReadMessageListener() {
|
||||
ReadMessage.readMessage(mRetrofit.getRetrofit(), mAccessToken, mMessageFullname, new ReadMessage.ReadMessageListener() {
|
||||
@Override
|
||||
public void readSuccess() {
|
||||
mMessageFullname = null;
|
||||
@@ -920,7 +1027,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
}
|
||||
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SEARCH: {
|
||||
Intent intent = new Intent(this, SearchActivity.class);
|
||||
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
startActivity(intent);
|
||||
break;
|
||||
}
|
||||
@@ -964,109 +1071,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
});
|
||||
navigationWrapper.floatingActionButton.setVisibility(hideFab ? View.GONE : View.VISIBLE);
|
||||
|
||||
subscribeSubredditChip.setOnClickListener(view -> {
|
||||
if (mAccessToken == null) {
|
||||
if (subscriptionReady) {
|
||||
subscriptionReady = false;
|
||||
if (getResources().getString(R.string.subscribe).contentEquals(subscribeSubredditChip.getText())) {
|
||||
SubredditSubscription.anonymousSubscribeToSubreddit(mExecutor, new Handler(),
|
||||
mRetrofit.getRetrofit(), mRedditDataRoomDatabase, subredditName,
|
||||
new SubredditSubscription.SubredditSubscriptionListener() {
|
||||
@Override
|
||||
public void onSubredditSubscriptionSuccess() {
|
||||
subscribeSubredditChip.setText(R.string.unsubscribe);
|
||||
subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(subscribedColor));
|
||||
makeSnackbar(R.string.subscribed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubredditSubscriptionFail() {
|
||||
makeSnackbar(R.string.subscribe_failed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
SubredditSubscription.anonymousUnsubscribeToSubreddit(mExecutor, new Handler(),
|
||||
mRedditDataRoomDatabase, subredditName,
|
||||
new SubredditSubscription.SubredditSubscriptionListener() {
|
||||
@Override
|
||||
public void onSubredditSubscriptionSuccess() {
|
||||
subscribeSubredditChip.setText(R.string.subscribe);
|
||||
subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(unsubscribedColor));
|
||||
makeSnackbar(R.string.unsubscribed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubredditSubscriptionFail() {
|
||||
makeSnackbar(R.string.unsubscribe_failed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (subscriptionReady) {
|
||||
subscriptionReady = false;
|
||||
if (getResources().getString(R.string.subscribe).contentEquals(subscribeSubredditChip.getText())) {
|
||||
SubredditSubscription.subscribeToSubreddit(mExecutor, new Handler(), mOauthRetrofit,
|
||||
mRetrofit.getRetrofit(), mAccessToken, subredditName, mAccountName, mRedditDataRoomDatabase,
|
||||
new SubredditSubscription.SubredditSubscriptionListener() {
|
||||
@Override
|
||||
public void onSubredditSubscriptionSuccess() {
|
||||
subscribeSubredditChip.setText(R.string.unsubscribe);
|
||||
subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(subscribedColor));
|
||||
makeSnackbar(R.string.subscribed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubredditSubscriptionFail() {
|
||||
makeSnackbar(R.string.subscribe_failed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
SubredditSubscription.unsubscribeToSubreddit(mExecutor, new Handler(), mOauthRetrofit,
|
||||
mAccessToken, subredditName, mAccountName, mRedditDataRoomDatabase,
|
||||
new SubredditSubscription.SubredditSubscriptionListener() {
|
||||
@Override
|
||||
public void onSubredditSubscriptionSuccess() {
|
||||
subscribeSubredditChip.setText(R.string.subscribe);
|
||||
subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(unsubscribedColor));
|
||||
makeSnackbar(R.string.unsubscribed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubredditSubscriptionFail() {
|
||||
makeSnackbar(R.string.unsubscribe_failed, false);
|
||||
subscriptionReady = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
CheckIsSubscribedToSubreddit.checkIsSubscribedToSubreddit(mExecutor, new Handler(),
|
||||
mRedditDataRoomDatabase, qualifiedName, mAccountQualifiedName,
|
||||
new CheckIsSubscribedToSubreddit.CheckIsSubscribedToSubredditListener() {
|
||||
@Override
|
||||
public void isSubscribed() {
|
||||
subscribeSubredditChip.setText(R.string.unsubscribe);
|
||||
subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(subscribedColor));
|
||||
subscriptionReady = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void isNotSubscribed() {
|
||||
subscribeSubredditChip.setText(R.string.subscribe);
|
||||
subscribeSubredditChip.setChipBackgroundColor(ColorStateList.valueOf(unsubscribedColor));
|
||||
subscriptionReady = true;
|
||||
}
|
||||
});
|
||||
|
||||
sectionsPagerAdapter = new SectionsPagerAdapter(this);
|
||||
viewPager2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
|
||||
@@ -1133,7 +1137,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
return true;
|
||||
} else if (itemId == R.id.action_search_view_subreddit_detail_activity) {
|
||||
Intent intent = new Intent(this, SearchActivity.class);
|
||||
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
intent.putExtra(SearchActivity.EXTRA_COMMUNITY_FULL_NAME, qualifiedName);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
@@ -1152,7 +1156,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
return true;
|
||||
}
|
||||
Intent selectUserFlairIntent = new Intent(this, SelectUserFlairActivity.class);
|
||||
selectUserFlairIntent.putExtra(SelectUserFlairActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
selectUserFlairIntent.putExtra(SelectUserFlairActivity.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
startActivity(selectUserFlairIntent);
|
||||
return true;
|
||||
} else if (itemId == R.id.action_add_to_multireddit_view_subreddit_detail_activity) {
|
||||
@@ -1164,13 +1168,14 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
startActivityForResult(intent, ADD_TO_MULTIREDDIT_REQUEST_CODE);
|
||||
} else if (itemId == R.id.action_add_to_post_filter_view_subreddit_detail_activity) {
|
||||
Intent intent = new Intent(this, PostFilterPreferenceActivity.class);
|
||||
intent.putExtra(PostFilterPreferenceActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(PostFilterPreferenceActivity.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
} else if (itemId == R.id.action_share_view_subreddit_detail_activity) {
|
||||
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
||||
shareIntent.setType("text/plain");
|
||||
shareIntent.putExtra(Intent.EXTRA_TEXT, qualifiedName);
|
||||
String baseURL = mRetrofit.getBaseURL().endsWith("/") ? mRetrofit.getBaseURL() : mRetrofit.getBaseURL() + "/";
|
||||
shareIntent.putExtra(Intent.EXTRA_TEXT, baseURL + "/" + qualifiedName);
|
||||
if (shareIntent.resolveActivity(getPackageManager()) != null) {
|
||||
startActivity(Intent.createChooser(shareIntent, getString(R.string.share)));
|
||||
} else {
|
||||
@@ -1179,13 +1184,13 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
return true;
|
||||
} else if (itemId == R.id.action_go_to_wiki_view_subreddit_detail_activity) {
|
||||
Intent wikiIntent = new Intent(this, WikiActivity.class);
|
||||
wikiIntent.putExtra(WikiActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
wikiIntent.putExtra(WikiActivity.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
wikiIntent.putExtra(WikiActivity.EXTRA_WIKI_PATH, "index");
|
||||
startActivity(wikiIntent);
|
||||
return true;
|
||||
} else if (itemId == R.id.action_contact_mods_view_subreddit_detail_activity) {
|
||||
Intent intent = new Intent(this, SendPrivateMessageActivity.class);
|
||||
intent.putExtra(SendPrivateMessageActivity.EXTRA_RECIPIENT_USERNAME, "r/" + subredditName);
|
||||
intent.putExtra(SendPrivateMessageActivity.EXTRA_RECIPIENT_USERNAME, "r/" + communityName);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
@@ -1199,19 +1204,19 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
if (data != null) {
|
||||
MultiReddit multiReddit = data.getParcelableExtra(MultiredditSelectionActivity.EXTRA_RETURN_MULTIREDDIT);
|
||||
if (multiReddit != null) {
|
||||
AddSubredditOrUserToMultiReddit.addSubredditOrUserToMultiReddit(mOauthRetrofit,
|
||||
mAccessToken, multiReddit.getPath(), subredditName,
|
||||
AddSubredditOrUserToMultiReddit.addSubredditOrUserToMultiReddit(mRetrofit.getRetrofit(),
|
||||
mAccessToken, multiReddit.getPath(), communityName,
|
||||
new AddSubredditOrUserToMultiReddit.AddSubredditOrUserToMultiRedditListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
Toast.makeText(ViewSubredditDetailActivity.this,
|
||||
getString(R.string.add_community_or_user_to_multireddit_success, subredditName, multiReddit.getDisplayName()), Toast.LENGTH_LONG).show();
|
||||
getString(R.string.add_community_or_user_to_multireddit_success, communityName, multiReddit.getDisplayName()), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(int code) {
|
||||
Toast.makeText(ViewSubredditDetailActivity.this,
|
||||
getString(R.string.add_community_or_user_to_multireddit_failed, subredditName, multiReddit.getDisplayName()), Toast.LENGTH_LONG).show();
|
||||
getString(R.string.add_community_or_user_to_multireddit_failed, communityName, multiReddit.getDisplayName()), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1274,39 +1279,39 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
switch (postType) {
|
||||
case PostTypeBottomSheetFragment.TYPE_TEXT:
|
||||
intent = new Intent(this, PostTextActivity.class);
|
||||
intent.putExtra(PostTextActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(PostTextActivity.EXTRA_SUBREDDIT_NAME, qualifiedName);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case PostTypeBottomSheetFragment.TYPE_LINK:
|
||||
intent = new Intent(this, PostLinkActivity.class);
|
||||
intent.putExtra(PostLinkActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(PostLinkActivity.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case PostTypeBottomSheetFragment.TYPE_IMAGE:
|
||||
intent = new Intent(this, PostImageActivity.class);
|
||||
intent.putExtra(PostImageActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(PostImageActivity.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case PostTypeBottomSheetFragment.TYPE_VIDEO:
|
||||
intent = new Intent(this, PostVideoActivity.class);
|
||||
intent.putExtra(PostVideoActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(PostVideoActivity.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case PostTypeBottomSheetFragment.TYPE_GALLERY:
|
||||
intent = new Intent(this, PostGalleryActivity.class);
|
||||
intent.putExtra(PostGalleryActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(PostGalleryActivity.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case PostTypeBottomSheetFragment.TYPE_POLL:
|
||||
intent = new Intent(this, PostPollActivity.class);
|
||||
intent.putExtra(PostPollActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(PostPollActivity.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postLayoutSelected(int postLayout) {
|
||||
mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, postLayout).apply();
|
||||
mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + communityName, postLayout).apply();
|
||||
sectionsPagerAdapter.changePostLayout(postLayout);
|
||||
}
|
||||
|
||||
@@ -1382,7 +1387,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
break;
|
||||
case FABMoreOptionsBottomSheetFragment.FAB_OPTION_SEARCH:
|
||||
Intent intent = new Intent(this, SearchActivity.class);
|
||||
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
startActivity(intent);
|
||||
break;
|
||||
case FABMoreOptionsBottomSheetFragment.FAB_OPTION_GO_TO_SUBREDDIT: {
|
||||
@@ -1460,7 +1465,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
if (subredditAutocompleteCall != null) {
|
||||
subredditAutocompleteCall.cancel();
|
||||
}
|
||||
subredditAutocompleteCall = mOauthRetrofit.create(RedditAPI.class).subredditAutocomplete(APIUtils.getOAuthHeader(mAccessToken),
|
||||
subredditAutocompleteCall = mRetrofit.getRetrofit().create(RedditAPI.class).subredditAutocomplete(APIUtils.getOAuthHeader(mAccessToken),
|
||||
editable.toString(), nsfw);
|
||||
subredditAutocompleteCall.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
@@ -1596,7 +1601,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
||||
SidebarFragment fragment = new SidebarFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(SidebarFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(SidebarFragment.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
bundle.putString(SidebarFragment.EXTRA_SUBREDDIT_NAME, communityName);
|
||||
bundle.putString(SidebarFragment.EXTRA_COMMUNITY_QUALIFIED_NAME, qualifiedName);
|
||||
fragment.setArguments(bundle);
|
||||
return fragment;
|
||||
|
||||
@@ -1154,7 +1154,8 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
||||
} else if (itemId == R.id.action_share_view_user_detail_activity) {
|
||||
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
||||
shareIntent.setType("text/plain");
|
||||
shareIntent.putExtra(Intent.EXTRA_TEXT, "https://www.reddit.com/user/" + username);
|
||||
String baseURL = mRetrofit.getBaseURL().endsWith("/") ? mRetrofit.getBaseURL() : mRetrofit.getBaseURL() + "/";
|
||||
shareIntent.putExtra(Intent.EXTRA_TEXT, baseURL + qualifiedName);
|
||||
if (shareIntent.resolveActivity(getPackageManager()) != null) {
|
||||
startActivity(Intent.createChooser(shareIntent, getString(R.string.share)));
|
||||
} else {
|
||||
|
||||
@@ -32,6 +32,7 @@ import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.toldi.infinityforlemmy.NetworkState;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.SaveComment;
|
||||
import eu.toldi.infinityforlemmy.SaveThing;
|
||||
import eu.toldi.infinityforlemmy.VoteThing;
|
||||
import eu.toldi.infinityforlemmy.activities.BaseActivity;
|
||||
@@ -76,7 +77,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
||||
}
|
||||
};
|
||||
private BaseActivity mActivity;
|
||||
private Retrofit mOauthRetrofit;
|
||||
private Retrofit retrofit;
|
||||
private Locale mLocale;
|
||||
private Markwon mMarkwon;
|
||||
private RecyclerView.RecycledViewPool recycledViewPool;
|
||||
@@ -109,7 +110,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
||||
String accountName, RetryLoadingMoreCallback retryLoadingMoreCallback) {
|
||||
super(DIFF_CALLBACK);
|
||||
mActivity = activity;
|
||||
mOauthRetrofit = oauthRetrofit;
|
||||
retrofit = oauthRetrofit;
|
||||
mCommentColor = customThemeWrapper.getCommentColor();
|
||||
int commentSpoilerBackgroundColor = mCommentColor | 0xFF000000;
|
||||
mLocale = locale;
|
||||
@@ -189,7 +190,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
||||
if (holder instanceof CommentViewHolder) {
|
||||
Comment comment = getItem(holder.getBindingAdapterPosition());
|
||||
if (comment != null) {
|
||||
String name = "r/" + comment.getCommunityName();
|
||||
String name = comment.getCommunityQualifiedName();
|
||||
((CommentViewHolder) holder).authorTextView.setText(name);
|
||||
((CommentViewHolder) holder).authorTextView.setTextColor(mSubredditColor);
|
||||
|
||||
@@ -436,6 +437,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
||||
if (comment != null) {
|
||||
Intent intent = new Intent(mActivity, ViewSubredditDetailActivity.class);
|
||||
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, comment.getCommunityName());
|
||||
intent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, comment.getCommunityQualifiedName());
|
||||
mActivity.startActivity(intent);
|
||||
}
|
||||
});
|
||||
@@ -468,7 +470,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
||||
Comment comment = getItem(getBindingAdapterPosition());
|
||||
if (comment != null) {
|
||||
Intent intent = new Intent(mActivity, ViewPostDetailActivity.class);
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, comment.getLinkId());
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, comment.getPostId());
|
||||
intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, comment.getId());
|
||||
mActivity.startActivity(intent);
|
||||
}
|
||||
@@ -536,7 +538,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
||||
comment.getScore() + comment.getVoteType()));
|
||||
|
||||
|
||||
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position1) {
|
||||
int currentPosition = getBindingAdapterPosition();
|
||||
@@ -606,7 +608,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
||||
comment.getScore() + comment.getVoteType()));
|
||||
|
||||
|
||||
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position1) {
|
||||
int currentPosition = getBindingAdapterPosition();
|
||||
@@ -646,9 +648,10 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
||||
}
|
||||
Comment comment = getItem(position);
|
||||
if (comment != null) {
|
||||
SaveComment saveComment = new SaveComment();
|
||||
if (comment.isSaved()) {
|
||||
comment.setSaved(false);
|
||||
SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, comment.getFullName(), new SaveThing.SaveThingListener() {
|
||||
saveComment.unsaveThing(retrofit, mAccessToken, comment.getId(), new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
comment.setSaved(false);
|
||||
@@ -669,7 +672,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
||||
});
|
||||
} else {
|
||||
comment.setSaved(true);
|
||||
SaveThing.saveThing(mOauthRetrofit, mAccessToken, comment.getFullName(), new SaveThing.SaveThingListener() {
|
||||
saveComment.saveThing(retrofit, mAccessToken, comment.getId(), new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
comment.setSaved(true);
|
||||
|
||||
@@ -42,6 +42,7 @@ import java.util.concurrent.Executor;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.SaveComment;
|
||||
import eu.toldi.infinityforlemmy.SaveThing;
|
||||
import eu.toldi.infinityforlemmy.SortType;
|
||||
import eu.toldi.infinityforlemmy.VoteThing;
|
||||
@@ -391,7 +392,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
|
||||
}
|
||||
|
||||
if (comment.getAuthorIconUrl() == null) {
|
||||
mFragment.loadIcon(comment.getAuthor(), (authorName, iconUrl) -> {
|
||||
mFragment.loadIcon(comment.getAuthorQualifiedName(), (authorName, iconUrl) -> {
|
||||
if (authorName.equals(comment.getAuthor())) {
|
||||
comment.setAuthorIconUrl(iconUrl);
|
||||
}
|
||||
@@ -536,7 +537,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
|
||||
((CommentFullyCollapsedViewHolder) holder).usernameTextView.setText(authorWithPrefix);
|
||||
|
||||
if (comment.getAuthorIconUrl() == null) {
|
||||
mFragment.loadIcon(comment.getAuthor(), (authorName, iconUrl) -> {
|
||||
mFragment.loadIcon(comment.getAuthorQualifiedName(), (authorName, iconUrl) -> {
|
||||
if (authorName.equals(comment.getAuthor())) {
|
||||
comment.setAuthorIconUrl(iconUrl);
|
||||
}
|
||||
@@ -856,6 +857,16 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
|
||||
}
|
||||
}
|
||||
|
||||
List<Comment> newComments = new ArrayList<>();
|
||||
for (int i = 0; i < comments.size(); i++) {
|
||||
if (loadedComments.contains(comments.get(i).getId())) {
|
||||
continue;
|
||||
}
|
||||
newComments.add(comments.get(i));
|
||||
loadedComments.add(comments.get(i).getId());
|
||||
}
|
||||
comments = (ArrayList<Comment>) newComments;
|
||||
|
||||
int sizeBefore = mVisibleComments.size();
|
||||
mVisibleComments.addAll(comments);
|
||||
for (int i = 0; i < comments.size(); i++) {
|
||||
@@ -1535,9 +1546,10 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
|
||||
Comment comment = getCurrentComment(this);
|
||||
if (comment != null) {
|
||||
int position = getBindingAdapterPosition();
|
||||
SaveComment saveComment = new SaveComment();
|
||||
if (comment.isSaved()) {
|
||||
comment.setSaved(false);
|
||||
SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, comment.getFullName(), new SaveThing.SaveThingListener() {
|
||||
saveComment.unsaveThing(mOauthRetrofit, mAccessToken, comment.getId(), new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
comment.setSaved(false);
|
||||
@@ -1558,7 +1570,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
|
||||
});
|
||||
} else {
|
||||
comment.setSaved(true);
|
||||
SaveThing.saveThing(mOauthRetrofit, mAccessToken, comment.getFullName(), new SaveThing.SaveThingListener() {
|
||||
saveComment.saveThing(mRetrofit, mAccessToken, comment.getId(), new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
comment.setSaved(true);
|
||||
@@ -1925,4 +1937,8 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
|
||||
((TextView) itemView).setTextColor(mColorAccent);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearLoadedComments() {
|
||||
loadedComments.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ import eu.toldi.infinityforlemmy.FetchGfycatOrRedgifsVideoLinks;
|
||||
import eu.toldi.infinityforlemmy.FetchStreamableVideo;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.SaveMemoryCenterInisdeDownsampleStrategy;
|
||||
import eu.toldi.infinityforlemmy.SavePost;
|
||||
import eu.toldi.infinityforlemmy.SaveThing;
|
||||
import eu.toldi.infinityforlemmy.StreamableVideo;
|
||||
import eu.toldi.infinityforlemmy.VoteThing;
|
||||
@@ -140,7 +141,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
private SharedPreferences mSharedPreferences;
|
||||
private SharedPreferences mCurrentAccountSharedPreferences;
|
||||
private Executor mExecutor;
|
||||
private Retrofit mOauthRetrofit;
|
||||
private Retrofit retrofit;
|
||||
private Retrofit mGfycatRetrofit;
|
||||
private Retrofit mRedgifsRetrofit;
|
||||
private Provider<StreamableAPI> mStreamableApiProvider;
|
||||
@@ -236,7 +237,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
mSharedPreferences = sharedPreferences;
|
||||
mCurrentAccountSharedPreferences = currentAccountSharedPreferences;
|
||||
mExecutor = executor;
|
||||
mOauthRetrofit = oauthRetrofit;
|
||||
retrofit = oauthRetrofit;
|
||||
mGfycatRetrofit = gfycatRetrofit;
|
||||
mRedgifsRetrofit = redgifsRetrofit;
|
||||
mStreamableApiProvider = streambleApiProvider;
|
||||
@@ -2326,7 +2327,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
|
||||
}
|
||||
|
||||
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position1) {
|
||||
int currentPosition = getBindingAdapterPosition();
|
||||
@@ -2418,7 +2419,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
|
||||
}
|
||||
|
||||
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position1) {
|
||||
int currentPosition = getBindingAdapterPosition();
|
||||
@@ -2476,10 +2477,10 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
SavePost savePost = new SavePost();
|
||||
if (post.isSaved()) {
|
||||
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
|
||||
SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, post.getFullName(),
|
||||
savePost.unsaveThing(retrofit, mAccessToken, post.getId(),
|
||||
new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
@@ -2503,7 +2504,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
});
|
||||
} else {
|
||||
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
|
||||
SaveThing.saveThing(mOauthRetrofit, mAccessToken, post.getFullName(),
|
||||
savePost.saveThing(retrofit, mAccessToken, post.getId(),
|
||||
new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
@@ -3652,7 +3653,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
|
||||
}
|
||||
|
||||
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position1) {
|
||||
int currentPosition = getBindingAdapterPosition();
|
||||
@@ -3744,7 +3745,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
|
||||
}
|
||||
|
||||
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position1) {
|
||||
int currentPosition = getBindingAdapterPosition();
|
||||
@@ -3804,9 +3805,10 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
}
|
||||
Post post = getItem(position);
|
||||
if (post != null) {
|
||||
SavePost savePost = new SavePost();
|
||||
if (post.isSaved()) {
|
||||
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
|
||||
SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, post.getFullName(),
|
||||
savePost.unsaveThing(retrofit, mAccessToken, post.getId(),
|
||||
new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
@@ -3830,7 +3832,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
||||
});
|
||||
} else {
|
||||
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
|
||||
SaveThing.saveThing(mOauthRetrofit, mAccessToken, post.getFullName(),
|
||||
savePost.saveThing(retrofit, mAccessToken, post.getId(),
|
||||
new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
|
||||
@@ -31,7 +31,7 @@ public class MarkdownBottomBarRecyclerViewAdapter extends RecyclerView.Adapter<R
|
||||
public static final int CODE_BLOCK = 9;
|
||||
public static final int UPLOAD_IMAGE = 10;
|
||||
|
||||
private static final int ITEM_COUNT = 10;
|
||||
private static final int ITEM_COUNT = 11;
|
||||
|
||||
private CustomThemeWrapper customThemeWrapper;
|
||||
private ItemClickListener itemClickListener;
|
||||
|
||||
@@ -64,6 +64,7 @@ import eu.toldi.infinityforlemmy.FetchStreamableVideo;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
|
||||
import eu.toldi.infinityforlemmy.SaveMemoryCenterInisdeDownsampleStrategy;
|
||||
import eu.toldi.infinityforlemmy.SavePost;
|
||||
import eu.toldi.infinityforlemmy.SaveThing;
|
||||
import eu.toldi.infinityforlemmy.StreamableVideo;
|
||||
import eu.toldi.infinityforlemmy.VoteThing;
|
||||
@@ -507,7 +508,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
} else {
|
||||
if (mPost.getSubredditIconUrl() == null) {
|
||||
LoadSubredditIcon.loadSubredditIcon(mExecutor, new Handler(),
|
||||
mRedditDataRoomDatabase, mPost.getSubredditNamePrefixed().substring(2),
|
||||
mRedditDataRoomDatabase, mPost.getSubredditNamePrefixed(),
|
||||
mAccessToken, mOauthRetrofit, mRetrofit, iconImageUrl -> {
|
||||
if (iconImageUrl == null || iconImageUrl.equals("")) {
|
||||
mGlide.load(R.drawable.subreddit_default_icon)
|
||||
@@ -1350,10 +1351,10 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
SavePost savePost = new SavePost();
|
||||
if (mPost.isSaved()) {
|
||||
mSaveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
|
||||
SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, mPost.getFullName(),
|
||||
savePost.unsaveThing(mOauthRetrofit, mAccessToken, mPost.getId(),
|
||||
new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
@@ -1373,7 +1374,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
||||
});
|
||||
} else {
|
||||
mSaveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
|
||||
SaveThing.saveThing(mOauthRetrofit, mAccessToken, mPost.getFullName(),
|
||||
savePost.saveThing(mRetrofit, mAccessToken, mPost.getId(),
|
||||
new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
|
||||
@@ -68,6 +68,7 @@ import eu.toldi.infinityforlemmy.FetchStreamableVideo;
|
||||
import eu.toldi.infinityforlemmy.MarkPostAsReadInterface;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.SaveMemoryCenterInisdeDownsampleStrategy;
|
||||
import eu.toldi.infinityforlemmy.SavePost;
|
||||
import eu.toldi.infinityforlemmy.SaveThing;
|
||||
import eu.toldi.infinityforlemmy.StreamableVideo;
|
||||
import eu.toldi.infinityforlemmy.VoteThing;
|
||||
@@ -145,7 +146,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
private SharedPreferences mSharedPreferences;
|
||||
private SharedPreferences mCurrentAccountSharedPreferences;
|
||||
private Executor mExecutor;
|
||||
private Retrofit mOauthRetrofit;
|
||||
private Retrofit retrofit;
|
||||
private Retrofit mGfycatRetrofit;
|
||||
private Retrofit mRedgifsRetrofit;
|
||||
private Provider<StreamableAPI> mStreamableApiProvider;
|
||||
@@ -249,7 +250,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
mSharedPreferences = sharedPreferences;
|
||||
mCurrentAccountSharedPreferences = currentAccountSharedPreferences;
|
||||
mExecutor = executor;
|
||||
mOauthRetrofit = oauthRetrofit;
|
||||
retrofit = oauthRetrofit;
|
||||
mGfycatRetrofit = gfycatRetrofit;
|
||||
mRedgifsRetrofit = redgifsRetrofit;
|
||||
mStreamableApiProvider = streamableApiProvider;
|
||||
@@ -1154,7 +1155,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
if (mHideSubredditAndUserPrefix) {
|
||||
((PostCompactBaseViewHolder) holder).nameTextView.setText(post.getSubredditName());
|
||||
} else {
|
||||
((PostCompactBaseViewHolder) holder).nameTextView.setText("r/" + post.getSubredditName());
|
||||
((PostCompactBaseViewHolder) holder).nameTextView.setText(post.getSubredditNamePrefixed());
|
||||
}
|
||||
} else {
|
||||
if (post.getAuthorIconUrl() == null) {
|
||||
@@ -2433,7 +2434,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
|
||||
}
|
||||
|
||||
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position1) {
|
||||
int currentPosition = getBindingAdapterPosition();
|
||||
@@ -2529,7 +2530,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
|
||||
}
|
||||
|
||||
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position1) {
|
||||
int currentPosition = getBindingAdapterPosition();
|
||||
@@ -2587,10 +2588,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
Toast.makeText(mActivity, R.string.login_first, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
SavePost savePost = new SavePost();
|
||||
if (post.isSaved()) {
|
||||
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
|
||||
SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, post.getFullName(),
|
||||
savePost.unsaveThing(retrofit, mAccessToken, post.getId(),
|
||||
new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
@@ -2614,7 +2615,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
});
|
||||
} else {
|
||||
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
|
||||
SaveThing.saveThing(mOauthRetrofit, mAccessToken, post.getFullName(),
|
||||
savePost.saveThing(retrofit, mAccessToken, post.getId(),
|
||||
new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
@@ -3792,7 +3793,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
|
||||
}
|
||||
|
||||
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position1) {
|
||||
int currentPosition = getBindingAdapterPosition();
|
||||
@@ -3888,7 +3889,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
|
||||
}
|
||||
|
||||
VoteThing.votePost(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
VoteThing.votePost(mActivity, retrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||
@Override
|
||||
public void onVoteThingSuccess(int position1) {
|
||||
int currentPosition = getBindingAdapterPosition();
|
||||
@@ -3948,9 +3949,10 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
}
|
||||
Post post = getItem(position);
|
||||
if (post != null) {
|
||||
SavePost postSave = new SavePost();
|
||||
if (post.isSaved()) {
|
||||
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
|
||||
SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, post.getFullName(),
|
||||
postSave.unsaveThing(retrofit, mAccessToken, post.getId(),
|
||||
new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
@@ -3974,7 +3976,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
});
|
||||
} else {
|
||||
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
|
||||
SaveThing.saveThing(mOauthRetrofit, mAccessToken, post.getFullName(),
|
||||
postSave.saveThing(retrofit, mAccessToken, post.getId(),
|
||||
new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
|
||||
@@ -33,8 +33,8 @@ import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
|
||||
import eu.toldi.infinityforlemmy.activities.BaseActivity;
|
||||
import eu.toldi.infinityforlemmy.asynctasks.CheckIsSubscribedToSubreddit;
|
||||
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.subreddit.CommunitySubscription;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditSubscription;
|
||||
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||
import pl.droidsonroids.gif.GifImageView;
|
||||
@@ -125,7 +125,7 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred
|
||||
if (isMultiSelection) {
|
||||
((DataViewHolder) holder).checkBox.performClick();
|
||||
} else {
|
||||
callback.subredditSelected(subredditData.getName(), LemmyUtils.actorID2FullName(subredditData.getActorId()), subredditData.getIconUrl());
|
||||
callback.subredditSelected(subredditData);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -158,10 +158,10 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred
|
||||
((DataViewHolder) holder).subscribeButton.setVisibility(View.VISIBLE);
|
||||
((DataViewHolder) holder).subscribeButton.setOnClickListener(view -> {
|
||||
if (accessToken != null) {
|
||||
SubredditSubscription.subscribeToSubreddit(executor, new Handler(),
|
||||
oauthRetrofit, retrofit, accessToken, subredditData.getName(),
|
||||
CommunitySubscription.subscribeToCommunity(executor, new Handler(),
|
||||
retrofit, accessToken, subredditData.getId(), LemmyUtils.actorID2FullName(subredditData.getActorId()),
|
||||
accountName, redditDataRoomDatabase,
|
||||
new SubredditSubscription.SubredditSubscriptionListener() {
|
||||
new CommunitySubscription.SubredditSubscriptionListener() {
|
||||
@Override
|
||||
public void onSubredditSubscriptionSuccess() {
|
||||
((DataViewHolder) holder).subscribeButton.setVisibility(View.GONE);
|
||||
@@ -174,9 +174,9 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred
|
||||
}
|
||||
});
|
||||
} else {
|
||||
SubredditSubscription.anonymousSubscribeToSubreddit(executor, new Handler(),
|
||||
CommunitySubscription.anonymousSubscribeToSubreddit(executor, new Handler(),
|
||||
retrofit, redditDataRoomDatabase, subredditData.getName(),
|
||||
new SubredditSubscription.SubredditSubscriptionListener() {
|
||||
new CommunitySubscription.SubredditSubscriptionListener() {
|
||||
@Override
|
||||
public void onSubredditSubscriptionSuccess() {
|
||||
((DataViewHolder) holder).subscribeButton.setVisibility(View.GONE);
|
||||
@@ -252,7 +252,7 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred
|
||||
public interface Callback {
|
||||
void retryLoadingMore();
|
||||
|
||||
void subredditSelected(String subredditName, String communityFullName,String iconUrl);
|
||||
void subredditSelected(SubredditData communityData);
|
||||
}
|
||||
|
||||
class DataViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@@ -149,39 +149,17 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
|
||||
|
||||
if (hasClearSelectionRow && viewHolder.getBindingAdapterPosition() == 0) {
|
||||
((SubredditViewHolder) viewHolder).subredditNameTextView.setText(R.string.all_communities);
|
||||
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(null, null, false));
|
||||
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(null));
|
||||
return;
|
||||
} else if (itemClickListener != null && !hasClearSelectionRow && viewHolder.getBindingAdapterPosition() == 0) {
|
||||
name = username;
|
||||
iconUrl = userIconUrl;
|
||||
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(name, iconUrl, true));
|
||||
} else if (hasClearSelectionRow && viewHolder.getBindingAdapterPosition() == 1) {
|
||||
name = username;
|
||||
iconUrl = userIconUrl;
|
||||
if (itemClickListener != null) {
|
||||
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(name, iconUrl, true));
|
||||
}
|
||||
} else {
|
||||
int offset;
|
||||
if (itemClickListener != null) {
|
||||
if (hasClearSelectionRow) {
|
||||
offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
|
||||
mFavoriteSubscribedSubredditData.size() + 4 : 2;
|
||||
} else {
|
||||
offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
|
||||
mFavoriteSubscribedSubredditData.size() + 3 : 1;
|
||||
}
|
||||
} else {
|
||||
offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
|
||||
mFavoriteSubscribedSubredditData.size() + 2 : 0;
|
||||
}
|
||||
|
||||
int offset = hasClearSelectionRow ? 1 : 0;
|
||||
SubscribedSubredditData communityData = mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset);
|
||||
name = mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getName();
|
||||
fullname = mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getQualified_name();
|
||||
iconUrl = mSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getIconUrl();
|
||||
|
||||
if (itemClickListener != null) {
|
||||
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(name, iconUrl, false));
|
||||
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(communityData));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,11 +197,12 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
|
||||
} else {
|
||||
offset = 1;
|
||||
}
|
||||
SubscribedSubredditData communityData = mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset);
|
||||
String name = mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getName();
|
||||
String iconUrl = mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getIconUrl();
|
||||
|
||||
if (itemClickListener != null) {
|
||||
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(name, iconUrl, false));
|
||||
viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(communityData));
|
||||
} else {
|
||||
viewHolder.itemView.setOnClickListener(view -> {
|
||||
Intent intent = new Intent(mActivity, ViewSubredditDetailActivity.class);
|
||||
@@ -250,26 +229,9 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (mSubscribedSubredditData != null) {
|
||||
if(mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) {
|
||||
if (itemClickListener != null) {
|
||||
if (hasClearSelectionRow) {
|
||||
return mSubscribedSubredditData.size() > 0 ?
|
||||
mFavoriteSubscribedSubredditData.size() + mSubscribedSubredditData.size() + 4 : 0;
|
||||
} else {
|
||||
return mSubscribedSubredditData.size() > 0 ?
|
||||
mFavoriteSubscribedSubredditData.size() + mSubscribedSubredditData.size() + 3 : 0;
|
||||
}
|
||||
}
|
||||
return mSubscribedSubredditData.size() > 0 ?
|
||||
mFavoriteSubscribedSubredditData.size() + mSubscribedSubredditData.size() + 2 : 0;
|
||||
}
|
||||
|
||||
if (itemClickListener != null) {
|
||||
if (hasClearSelectionRow) {
|
||||
return mSubscribedSubredditData.size() > 0 ? mSubscribedSubredditData.size() + 2 : 0;
|
||||
} else {
|
||||
return mSubscribedSubredditData.size() > 0 ? mSubscribedSubredditData.size() + 1 : 0;
|
||||
}
|
||||
return mSubscribedSubredditData.size() > 0 ? mSubscribedSubredditData.size() + ((hasClearSelectionRow) ? 1 : 0) : 0;
|
||||
}
|
||||
|
||||
return mSubscribedSubredditData.size();
|
||||
@@ -347,7 +309,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
|
||||
}
|
||||
|
||||
public interface ItemClickListener {
|
||||
void onClick(String name, String iconUrl, boolean subredditIsUser);
|
||||
void onClick(SubscribedSubredditData subredditData);
|
||||
}
|
||||
|
||||
class SubredditViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@@ -26,11 +26,11 @@ import java.util.concurrent.Executor;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.activities.BaseActivity;
|
||||
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||
import pl.droidsonroids.gif.GifImageView;
|
||||
|
||||
public class HeaderSectionRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
@@ -65,7 +65,7 @@ public class HeaderSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
|
||||
requireAuthToAccountSection = securitySharedPreferences.getBoolean(SharedPreferencesUtils.REQUIRE_AUTHENTICATION_TO_GO_TO_ACCOUNT_SECTION_IN_NAVIGATION_DRAWER, false);
|
||||
showAvatarOnTheRightInTheNavigationDrawer = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_AVATAR_ON_THE_RIGHT, false);
|
||||
showAvatarOnTheRightInTheNavigationDrawer = navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_AVATAR_ON_THE_RIGHT, false);
|
||||
this.hideKarma = navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_ACCOUNT_KARMA_NAV_BAR, false);
|
||||
this.hideKarma = true;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
||||
@@ -50,7 +50,7 @@ public class NavigationDrawerRecyclerViewMergedAdapter {
|
||||
accountSectionRecyclerViewAdapter = new AccountSectionRecyclerViewAdapter(baseActivity, customThemeWrapper,
|
||||
navigationDrawerSharedPreferences, accountName != null, itemClickListener);
|
||||
redditSectionRecyclerViewAdapter = new RedditSectionRecyclerViewAdapter(baseActivity, customThemeWrapper,
|
||||
navigationDrawerSharedPreferences, itemClickListener);
|
||||
navigationDrawerSharedPreferences, itemClickListener, accountName != null);
|
||||
postSectionRecyclerViewAdapter = new PostSectionRecyclerViewAdapter(baseActivity, customThemeWrapper,
|
||||
navigationDrawerSharedPreferences, accountName != null, itemClickListener);
|
||||
preferenceSectionRecyclerViewAdapter = new PreferenceSectionRecyclerViewAdapter(baseActivity, customThemeWrapper,
|
||||
|
||||
@@ -24,6 +24,9 @@ public class RedditSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
|
||||
private static final int VIEW_TYPE_MENU_ITEM = 2;
|
||||
private static final int REDDIT_SECTION_ITEMS = 1;
|
||||
|
||||
private static final int REDDIT_SECTION_ANONYMOUS_ITEMS = 2;
|
||||
private final boolean isLoggedIn;
|
||||
|
||||
private BaseActivity baseActivity;
|
||||
private int primaryTextColor;
|
||||
private int secondaryTextColor;
|
||||
@@ -33,13 +36,14 @@ public class RedditSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
|
||||
|
||||
public RedditSectionRecyclerViewAdapter(BaseActivity baseActivity, CustomThemeWrapper customThemeWrapper,
|
||||
SharedPreferences navigationDrawerSharedPreferences,
|
||||
NavigationDrawerRecyclerViewMergedAdapter.ItemClickListener itemClickListener) {
|
||||
NavigationDrawerRecyclerViewMergedAdapter.ItemClickListener itemClickListener, boolean isLoggedIn) {
|
||||
this.baseActivity = baseActivity;
|
||||
primaryTextColor = customThemeWrapper.getPrimaryTextColor();
|
||||
secondaryTextColor = customThemeWrapper.getSecondaryTextColor();
|
||||
primaryIconColor = customThemeWrapper.getPrimaryIconColor();
|
||||
collapseRedditSection = navigationDrawerSharedPreferences.getBoolean(SharedPreferencesUtils.COLLAPSE_REDDIT_SECTION, false);
|
||||
this.itemClickListener = itemClickListener;
|
||||
this.isLoggedIn = isLoggedIn;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,6 +92,9 @@ public class RedditSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
|
||||
stringId = R.string.trending;
|
||||
drawableId = R.drawable.ic_trending_24dp;
|
||||
break;
|
||||
case 2:
|
||||
stringId = R.string.anonymous_account_instance;
|
||||
drawableId = R.drawable.ic_account_circle_24dp;
|
||||
}
|
||||
|
||||
((MenuItemViewHolder) holder).menuTextView.setText(stringId);
|
||||
@@ -99,7 +106,7 @@ public class RedditSectionRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return collapseRedditSection ? 1 : REDDIT_SECTION_ITEMS + 1;
|
||||
return !collapseRedditSection ? (isLoggedIn ? REDDIT_SECTION_ITEMS + 1 : REDDIT_SECTION_ANONYMOUS_ITEMS + 1) : 1;
|
||||
}
|
||||
|
||||
class MenuGroupTitleViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@@ -5,13 +5,23 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||
import eu.toldi.infinityforlemmy.dto.AccountLoginDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.CommentDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.CommentVoteDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.EditCommentDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.FollowCommunityDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.PostVoteDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.SaveCommentDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.SavePostDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.SubmitPostDTO;
|
||||
import okhttp3.MultipartBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Header;
|
||||
import retrofit2.http.Headers;
|
||||
import retrofit2.http.Multipart;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.PUT;
|
||||
import retrofit2.http.Part;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
public interface LemmyAPI {
|
||||
@@ -28,6 +38,10 @@ public interface LemmyAPI {
|
||||
@GET("api/v3/post")
|
||||
Call<String> postInfo(@Query("id") Integer postID, @Query("comment_id") Integer comment_id, @Query("auth") String access_token);
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST("api/v3/post")
|
||||
Call<String> postCreate(@Body SubmitPostDTO params);
|
||||
|
||||
@GET("api/v3/user")
|
||||
ListenableFuture<Response<String>> getUserPosts(
|
||||
@Query("username") String username,
|
||||
@@ -37,6 +51,16 @@ public interface LemmyAPI {
|
||||
@Query("saved_only") Boolean saved_only,
|
||||
@Query("auth") String access_token);
|
||||
|
||||
@GET("api/v3/user")
|
||||
Call<String> getUserComments(
|
||||
@Query("username") String username,
|
||||
@Query("sort") String sort,
|
||||
@Query("page") Integer page,
|
||||
@Query("limit") Integer limit,
|
||||
@Query("saved_only") Boolean saved_only,
|
||||
@Query("auth") String access_token);
|
||||
|
||||
|
||||
@GET("api/v3/community/list")
|
||||
Call<String> listCommunities(
|
||||
@Query("type_") String type_,
|
||||
@@ -66,6 +90,18 @@ public interface LemmyAPI {
|
||||
@POST("api/v3/comment/like")
|
||||
Call<String> commentLike(@Body CommentVoteDTO params);
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST("api/v3/community/follow")
|
||||
Call<String> communityFollow(@Body FollowCommunityDTO params);
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@PUT("api/v3/post/save")
|
||||
Call<String> postSave(@Body SavePostDTO params);
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@PUT("api/v3/comment/save")
|
||||
Call<String> commentSave(@Body SaveCommentDTO params);
|
||||
|
||||
@GET("api/v3/comment/list")
|
||||
Call<String> getComments(
|
||||
@Query("type_") String type,
|
||||
@@ -112,4 +148,15 @@ public interface LemmyAPI {
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST("api/v3/comment")
|
||||
Call<String> postComment(@Body CommentDTO params);
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@PUT("api/v3/comment")
|
||||
Call<String> commentEdit(@Body EditCommentDTO params);
|
||||
|
||||
@Multipart
|
||||
@POST("/pictrs/image")
|
||||
Call<String> uploadImage(
|
||||
@Header("Cookie") String token,
|
||||
@Part MultipartBody.Part filePart
|
||||
);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class LoadSubredditIcon {
|
||||
String iconImageUrl = subredditDao.getSubredditData(subredditName).getIconUrl();
|
||||
handler.post(() -> loadSubredditIconAsyncTaskListener.loadIconSuccess(iconImageUrl));
|
||||
} else {
|
||||
handler.post(() -> FetchSubredditData.fetchSubredditData(oauthRetrofit, retrofit, subredditName, accessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
handler.post(() -> FetchSubredditData.fetchSubredditData(retrofit, subredditName, accessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData1, int nCurrentOnlineSubscribers) {
|
||||
ArrayList<SubredditData> singleSubredditDataList = new ArrayList<>();
|
||||
|
||||
@@ -112,7 +112,7 @@ public class CommentMoreBottomSheetFragment extends LandscapeExpandedRoundedBott
|
||||
|
||||
editTextView.setOnClickListener(view -> {
|
||||
Intent intent = new Intent(activity, EditCommentActivity.class);
|
||||
intent.putExtra(EditCommentActivity.EXTRA_FULLNAME, comment.getFullName());
|
||||
intent.putExtra(EditCommentActivity.EXTRA_FULLNAME, comment.getId());
|
||||
intent.putExtra(EditCommentActivity.EXTRA_CONTENT, comment.getCommentMarkdown());
|
||||
intent.putExtra(EditCommentActivity.EXTRA_POSITION, bundle.getInt(EXTRA_POSITION));
|
||||
if (activity instanceof ViewPostDetailActivity) {
|
||||
|
||||
@@ -38,12 +38,6 @@ public class PostTypeBottomSheetFragment extends LandscapeExpandedRoundedBottomS
|
||||
TextView linkTypeTextView;
|
||||
@BindView(R.id.image_type_linear_layout_post_type_bottom_sheet_fragment)
|
||||
TextView imageTypeTextView;
|
||||
@BindView(R.id.video_type_linear_layout_post_type_bottom_sheet_fragment)
|
||||
TextView videoTypeTextView;
|
||||
@BindView(R.id.gallery_type_linear_layout_post_type_bottom_sheet_fragment)
|
||||
TextView galleryTypeTextView;
|
||||
@BindView(R.id.poll_type_linear_layout_post_type_bottom_sheet_fragment)
|
||||
TextView pollTypeTextView;
|
||||
private BaseActivity activity;
|
||||
|
||||
public PostTypeBottomSheetFragment() {
|
||||
@@ -76,20 +70,6 @@ public class PostTypeBottomSheetFragment extends LandscapeExpandedRoundedBottomS
|
||||
dismiss();
|
||||
});
|
||||
|
||||
videoTypeTextView.setOnClickListener(view -> {
|
||||
((PostTypeSelectionCallback) activity).postTypeSelected(TYPE_VIDEO);
|
||||
dismiss();
|
||||
});
|
||||
|
||||
galleryTypeTextView.setOnClickListener(view -> {
|
||||
((PostTypeSelectionCallback) activity).postTypeSelected(TYPE_GALLERY);
|
||||
dismiss();
|
||||
});
|
||||
|
||||
pollTypeTextView.setOnClickListener(view -> {
|
||||
((PostTypeSelectionCallback) activity).postTypeSelected(TYPE_POLL);
|
||||
dismiss();
|
||||
});
|
||||
|
||||
if (activity.typeface != null) {
|
||||
Utils.setFontToAllTextViews(rootView, activity.typeface);
|
||||
|
||||
@@ -16,16 +16,13 @@ import java.util.Locale;
|
||||
|
||||
import eu.toldi.infinityforlemmy.NetworkState;
|
||||
import eu.toldi.infinityforlemmy.SortType;
|
||||
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
||||
import eu.toldi.infinityforlemmy.post.PostPagingSource;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.JSONUtils;
|
||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class CommentDataSource extends PageKeyedDataSource<String, Comment> {
|
||||
public class CommentDataSource extends PageKeyedDataSource<Integer, Comment> {
|
||||
|
||||
private Retrofit retrofit;
|
||||
private Locale locale;
|
||||
@@ -39,8 +36,8 @@ public class CommentDataSource extends PageKeyedDataSource<String, Comment> {
|
||||
private MutableLiveData<NetworkState> initialLoadStateLiveData;
|
||||
private MutableLiveData<Boolean> hasPostLiveData;
|
||||
|
||||
private LoadParams<String> params;
|
||||
private LoadCallback<String, Comment> callback;
|
||||
private LoadParams<Integer> params;
|
||||
private LoadCallback<Integer, Comment> callback;
|
||||
|
||||
CommentDataSource(Retrofit retrofit, Locale locale, @Nullable String accessToken, String username, SortType sortType,
|
||||
boolean areSavedComments) {
|
||||
@@ -72,42 +69,27 @@ public class CommentDataSource extends PageKeyedDataSource<String, Comment> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadInitial(@NonNull LoadInitialParams<String> params, @NonNull LoadInitialCallback<String, Comment> callback) {
|
||||
public void loadInitial(@NonNull LoadInitialParams<Integer> params, @NonNull LoadInitialCallback<Integer, Comment> callback) {
|
||||
initialLoadStateLiveData.postValue(NetworkState.LOADING);
|
||||
|
||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||
Call<String> commentsCall;
|
||||
if (areSavedComments) {
|
||||
commentsCall = api.getUserSavedCommentsOauth(username, PostPagingSource.USER_WHERE_SAVED,
|
||||
null, sortType.getType(), sortType.getTime(),
|
||||
APIUtils.getOAuthHeader(accessToken));
|
||||
} else {
|
||||
if (accessToken == null) {
|
||||
commentsCall = api.getUserComments(username, null, sortType.getType(),
|
||||
sortType.getTime());
|
||||
} else {
|
||||
commentsCall = api.getUserCommentsOauth(APIUtils.getOAuthHeader(accessToken), username,
|
||||
null, sortType.getType(), sortType.getTime());
|
||||
}
|
||||
}
|
||||
LemmyAPI api = retrofit.create(LemmyAPI.class);
|
||||
Call<String> commentsCall = api.getUserComments(username, sortType.getType().value, 1, 25, areSavedComments, accessToken);
|
||||
|
||||
commentsCall.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
new ParseCommentAsyncTask(response.body(), locale, new ParseCommentAsyncTask.ParseCommentAsyncTaskListener() {
|
||||
@Override
|
||||
public void parseSuccessful(ArrayList<Comment> comments, String after) {
|
||||
if (comments.size() == 0) {
|
||||
public void parseSuccessful(ArrayList<Comment> comments, Integer after) {
|
||||
if (comments.isEmpty()) {
|
||||
callback.onResult(comments, null, null);
|
||||
hasPostLiveData.postValue(false);
|
||||
} else {
|
||||
hasPostLiveData.postValue(true);
|
||||
callback.onResult(comments, null, 2);
|
||||
}
|
||||
|
||||
if (after == null || after.equals("") || after.equals("null")) {
|
||||
callback.onResult(comments, null, null);
|
||||
} else {
|
||||
callback.onResult(comments, null, after);
|
||||
}
|
||||
initialLoadStateLiveData.postValue(NetworkState.LOADED);
|
||||
}
|
||||
|
||||
@@ -129,39 +111,27 @@ public class CommentDataSource extends PageKeyedDataSource<String, Comment> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadBefore(@NonNull LoadParams<String> params, @NonNull LoadCallback<String, Comment> callback) {
|
||||
public void loadBefore(@NonNull LoadParams<Integer> params, @NonNull LoadCallback<Integer, Comment> callback) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadAfter(@NonNull LoadParams<String> params, @NonNull LoadCallback<String, Comment> callback) {
|
||||
public void loadAfter(@NonNull LoadParams<Integer> params, @NonNull LoadCallback<Integer, Comment> callback) {
|
||||
this.params = params;
|
||||
this.callback = callback;
|
||||
|
||||
paginationNetworkStateLiveData.postValue(NetworkState.LOADING);
|
||||
|
||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||
Call<String> commentsCall;
|
||||
if (areSavedComments) {
|
||||
commentsCall = api.getUserSavedCommentsOauth(username, PostPagingSource.USER_WHERE_SAVED, params.key,
|
||||
sortType.getType(), sortType.getTime(), APIUtils.getOAuthHeader(accessToken));
|
||||
} else {
|
||||
if (accessToken == null) {
|
||||
commentsCall = api.getUserComments(username, params.key, sortType.getType(),
|
||||
sortType.getTime());
|
||||
} else {
|
||||
commentsCall = api.getUserCommentsOauth(APIUtils.getOAuthHeader(accessToken),
|
||||
username, params.key, sortType.getType(), sortType.getTime());
|
||||
}
|
||||
}
|
||||
LemmyAPI api = retrofit.create(LemmyAPI.class);
|
||||
Call<String> commentsCall = api.getUserComments(username, sortType.getType().value, params.key, 25, areSavedComments, accessToken);
|
||||
commentsCall.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
new ParseCommentAsyncTask(response.body(), locale, new ParseCommentAsyncTask.ParseCommentAsyncTaskListener() {
|
||||
@Override
|
||||
public void parseSuccessful(ArrayList<Comment> comments, String after) {
|
||||
if (after == null || after.equals("") || after.equals("null")) {
|
||||
public void parseSuccessful(ArrayList<Comment> comments, Integer after) {
|
||||
if (comments.isEmpty()) {
|
||||
callback.onResult(comments, null);
|
||||
} else {
|
||||
callback.onResult(comments, after);
|
||||
@@ -187,7 +157,7 @@ public class CommentDataSource extends PageKeyedDataSource<String, Comment> {
|
||||
}
|
||||
|
||||
private static class ParseCommentAsyncTask extends AsyncTask<Void, ArrayList<Comment>, ArrayList<Comment>> {
|
||||
private String after;
|
||||
private Integer after;
|
||||
private Locale locale;
|
||||
private JSONArray commentsJSONArray;
|
||||
private boolean parseFailed;
|
||||
@@ -197,9 +167,8 @@ public class CommentDataSource extends PageKeyedDataSource<String, Comment> {
|
||||
this.locale = locale;
|
||||
this.parseCommentAsyncTaskListener = parseCommentAsyncTaskListener;
|
||||
try {
|
||||
JSONObject data = new JSONObject(response).getJSONObject(JSONUtils.DATA_KEY);
|
||||
commentsJSONArray = data.getJSONArray(JSONUtils.CHILDREN_KEY);
|
||||
after = data.getString(JSONUtils.AFTER_KEY);
|
||||
JSONObject data = new JSONObject(response);
|
||||
commentsJSONArray = data.getJSONArray("comments");
|
||||
parseFailed = false;
|
||||
} catch (JSONException e) {
|
||||
parseFailed = true;
|
||||
@@ -216,7 +185,7 @@ public class CommentDataSource extends PageKeyedDataSource<String, Comment> {
|
||||
ArrayList<Comment> comments = new ArrayList<>();
|
||||
for (int i = 0; i < commentsJSONArray.length(); i++) {
|
||||
try {
|
||||
JSONObject commentJSON = commentsJSONArray.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY);
|
||||
JSONObject commentJSON = commentsJSONArray.getJSONObject(i);
|
||||
comments.add(ParseComment.parseSingleComment(commentJSON));
|
||||
} catch (JSONException ignored) {
|
||||
}
|
||||
@@ -235,7 +204,7 @@ public class CommentDataSource extends PageKeyedDataSource<String, Comment> {
|
||||
}
|
||||
|
||||
interface ParseCommentAsyncTaskListener {
|
||||
void parseSuccessful(ArrayList<Comment> comments, String after);
|
||||
void parseSuccessful(ArrayList<Comment> comments, Integer page);
|
||||
|
||||
void parseFailed();
|
||||
}
|
||||
|
||||
@@ -9,16 +9,22 @@ import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import eu.toldi.infinityforlemmy.markdown.MarkdownUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.JSONUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
|
||||
|
||||
@@ -34,7 +40,6 @@ public class ParseComment {
|
||||
|
||||
ArrayList<Comment> expandedNewComments = new ArrayList<>();
|
||||
ArrayList<Integer> moreChildrenIds = new ArrayList<>();
|
||||
ArrayList<Comment> newComments = new ArrayList<>();
|
||||
|
||||
|
||||
Map<Integer, Comment> parsedComments = new HashMap<>();
|
||||
@@ -49,8 +54,13 @@ public class ParseComment {
|
||||
}
|
||||
}
|
||||
Comment parentComment = (commentId != null) ? parsedComments.get(commentId) : null;
|
||||
if (parentComment != null && parentComment.getDepth() == 0)
|
||||
parentComment = null;
|
||||
if (parentComment != null) {
|
||||
if (parentComment.getDepth() == 0) {
|
||||
parentComment = null;
|
||||
} else {
|
||||
expandedNewComments.add(parentComment);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = orderedComments.size() - 1; i >= 0; i--) {
|
||||
Comment c = orderedComments.get(i);
|
||||
@@ -64,9 +74,7 @@ public class ParseComment {
|
||||
}
|
||||
|
||||
//Add all comments to newComments
|
||||
for (int i = 0; i < topLevelComments.size(); i++) {
|
||||
newComments.add(topLevelComments.get(i));
|
||||
}
|
||||
ArrayList<Comment> newComments = new ArrayList<>(topLevelComments);
|
||||
|
||||
expandChildren(newComments, expandedNewComments, expandChildren);
|
||||
|
||||
@@ -281,15 +289,32 @@ public class ParseComment {
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
commentTimeMillis = ZonedDateTime.parse(commentObj.getString("published"),
|
||||
DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneId.of("Z"))).toInstant().toEpochMilli();
|
||||
} else {
|
||||
String dateStr = commentObj.getString("published");
|
||||
|
||||
dateStr = dateStr.substring(0, dateStr.lastIndexOf(".") + 4) + 'Z';
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault());
|
||||
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
try {
|
||||
Date date = sdf.parse(dateStr);
|
||||
if (date != null) {
|
||||
commentTimeMillis = date.getTime();
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
String commentMarkdown = commentObj.getString("content");
|
||||
String commentRawText = commentObj.getString("content");
|
||||
String content = MarkdownUtils.processImageCaptions(commentObj.getString("content"), "Image");
|
||||
String commentMarkdown = content;
|
||||
String commentRawText = content;
|
||||
String linkId = postObj.getString("id");
|
||||
String communityName = communityObj.getString("name");
|
||||
String communityQualifiedName = communityObj.getString("actor_id");
|
||||
String communityQualifiedName = LemmyUtils.actorID2FullName(communityObj.getString("actor_id"));
|
||||
|
||||
int score = countsObj.getInt("score");
|
||||
int voteType = (jsonObject.isNull("my_vote")) ? 0 : jsonObject.getInt("my_vote");
|
||||
if (voteType != 0)
|
||||
score -= 1;
|
||||
boolean isSubmitter = creatorObj.getInt("id") == postObj.getInt("creator_id");
|
||||
String distinguished = commentObj.getString("distinguished");
|
||||
String permalink = commentObj.getString("ap_id");
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package eu.toldi.infinityforlemmy.dto;
|
||||
|
||||
public class EditCommentDTO {
|
||||
|
||||
private int comment_id;
|
||||
private String content;
|
||||
private Integer language_id;
|
||||
private String form_id;
|
||||
private String auth;
|
||||
|
||||
public EditCommentDTO(int comment_id, String content, Integer language_id, String form_id, String auth) {
|
||||
this.comment_id = comment_id;
|
||||
this.content = content;
|
||||
this.language_id = language_id;
|
||||
this.form_id = form_id;
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public int getComment_id() {
|
||||
return comment_id;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public Integer getLanguage_id() {
|
||||
return language_id;
|
||||
}
|
||||
|
||||
public String getForm_id() {
|
||||
return form_id;
|
||||
}
|
||||
|
||||
public String getAuth() {
|
||||
return auth;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package eu.toldi.infinityforlemmy.dto;
|
||||
|
||||
public class FollowCommunityDTO {
|
||||
|
||||
private int community_id;
|
||||
private boolean follow;
|
||||
private String auth;
|
||||
|
||||
public FollowCommunityDTO(int community_id, boolean follow, String auth) {
|
||||
this.community_id = community_id;
|
||||
this.follow = follow;
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public int getCommunity_id() {
|
||||
return community_id;
|
||||
}
|
||||
|
||||
public boolean isFollow() {
|
||||
return follow;
|
||||
}
|
||||
|
||||
public String getAuth() {
|
||||
return auth;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package eu.toldi.infinityforlemmy.dto;
|
||||
|
||||
public class SaveCommentDTO {
|
||||
|
||||
private int comment_id;
|
||||
private boolean save;
|
||||
private String auth;
|
||||
|
||||
public SaveCommentDTO(int comment_id, boolean save, String auth) {
|
||||
this.comment_id = comment_id;
|
||||
this.save = save;
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public int getComment_id() {
|
||||
return comment_id;
|
||||
}
|
||||
|
||||
public boolean isSave() {
|
||||
return save;
|
||||
}
|
||||
|
||||
public String getAuth() {
|
||||
return auth;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package eu.toldi.infinityforlemmy.dto;
|
||||
|
||||
public class SavePostDTO {
|
||||
|
||||
|
||||
private int post_id;
|
||||
private boolean save;
|
||||
private String auth;
|
||||
|
||||
public SavePostDTO(int post_id, boolean save, String auth) {
|
||||
this.post_id = post_id;
|
||||
this.save = save;
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public int getPost_id() {
|
||||
return post_id;
|
||||
}
|
||||
|
||||
public boolean isSave() {
|
||||
return save;
|
||||
}
|
||||
|
||||
public String getAuth() {
|
||||
return auth;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package eu.toldi.infinityforlemmy.dto;
|
||||
|
||||
public class SubmitPostDTO {
|
||||
|
||||
private String name;
|
||||
private int community_id;
|
||||
private String url;
|
||||
private String body;
|
||||
private String honeypot;
|
||||
private boolean nsfw;
|
||||
private Integer language_id;
|
||||
private String auth;
|
||||
|
||||
public SubmitPostDTO(String name, int community_id, String url, String body, String honeypot, boolean nsfw, Integer language_id, String auth) {
|
||||
this.name = name;
|
||||
this.community_id = community_id;
|
||||
this.url = url;
|
||||
this.body = body;
|
||||
this.honeypot = honeypot;
|
||||
this.nsfw = nsfw;
|
||||
this.language_id = language_id;
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getCommunity_id() {
|
||||
return community_id;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public String getHoneypot() {
|
||||
return honeypot;
|
||||
}
|
||||
|
||||
public boolean isNsfw() {
|
||||
return nsfw;
|
||||
}
|
||||
|
||||
public Integer getLanguage_id() {
|
||||
return language_id;
|
||||
}
|
||||
|
||||
public String getAuth() {
|
||||
return auth;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
package eu.toldi.infinityforlemmy.events;
|
||||
|
||||
import eu.toldi.infinityforlemmy.post.Post;
|
||||
|
||||
public class SubmitImagePostEvent {
|
||||
public boolean postSuccess;
|
||||
public String errorMessage;
|
||||
public Post post;
|
||||
|
||||
public SubmitImagePostEvent(boolean postSuccess, String errorMessage) {
|
||||
public SubmitImagePostEvent(boolean postSuccess, String errorMessage, Post post) {
|
||||
this.postSuccess = postSuccess;
|
||||
this.errorMessage = errorMessage;
|
||||
this.post = post;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,6 @@ import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
|
||||
/**
|
||||
@@ -82,9 +81,6 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
|
||||
@Named("no_oauth")
|
||||
RetrofitHolder mRetrofit;
|
||||
@Inject
|
||||
@Named("oauth")
|
||||
Retrofit mOauthRetrofit;
|
||||
@Inject
|
||||
RedditDataRoomDatabase mRedditDataRoomDatabase;
|
||||
@Inject
|
||||
@Named("default")
|
||||
@@ -253,6 +249,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
|
||||
|
||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||
|
||||
|
||||
new Handler().postDelayed(() -> bindView(resources), 0);
|
||||
|
||||
return rootView;
|
||||
@@ -263,7 +260,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
|
||||
mLinearLayoutManager = new LinearLayoutManagerBugFixed(mActivity);
|
||||
mCommentRecyclerView.setLayoutManager(mLinearLayoutManager);
|
||||
|
||||
mAdapter = new CommentsListingRecyclerViewAdapter(mActivity, mOauthRetrofit, customThemeWrapper,
|
||||
mAdapter = new CommentsListingRecyclerViewAdapter(mActivity, mRetrofit.getRetrofit(), customThemeWrapper,
|
||||
getResources().getConfiguration().locale, mSharedPreferences,
|
||||
getArguments().getString(EXTRA_ACCESS_TOKEN), getArguments().getString(EXTRA_ACCOUNT_NAME),
|
||||
() -> mCommentViewModel.retryLoadingMore());
|
||||
@@ -294,15 +291,11 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
|
||||
|
||||
CommentViewModel.Factory factory;
|
||||
|
||||
if (mAccessToken == null) {
|
||||
factory = new CommentViewModel.Factory(mRetrofit.getRetrofit(),
|
||||
resources.getConfiguration().locale, null, username, sortType,
|
||||
getArguments().getBoolean(EXTRA_ARE_SAVED_COMMENTS));
|
||||
} else {
|
||||
factory = new CommentViewModel.Factory(mOauthRetrofit,
|
||||
resources.getConfiguration().locale, mAccessToken, username, sortType,
|
||||
getArguments().getBoolean(EXTRA_ARE_SAVED_COMMENTS));
|
||||
}
|
||||
|
||||
factory = new CommentViewModel.Factory(mRetrofit.getRetrofit(),
|
||||
resources.getConfiguration().locale, mAccessToken, username, sortType,
|
||||
getArguments().getBoolean(EXTRA_ARE_SAVED_COMMENTS));
|
||||
|
||||
|
||||
mCommentViewModel = new ViewModelProvider(this, factory).get(CommentViewModel.class);
|
||||
mCommentViewModel.getComments().observe(getViewLifecycleOwner(), comments -> mAdapter.submitList(comments));
|
||||
|
||||
@@ -380,7 +380,7 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato
|
||||
if (historyType == HISTORY_TYPE_READ_POSTS) {
|
||||
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.HISTORY_POST_LAYOUT_READ_POST, defaultPostLayout);
|
||||
|
||||
mAdapter = new HistoryPostRecyclerViewAdapter(activity, this, mExecutor, mOauthRetrofit, mGfycatRetrofit,
|
||||
mAdapter = new HistoryPostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit.getRetrofit(), mGfycatRetrofit,
|
||||
mRedgifsRetrofit, mStreamableApiProvider, mCustomThemeWrapper, locale,
|
||||
accessToken, accountName, postType, postLayout, true,
|
||||
mSharedPreferences, mCurrentAccountSharedPreferences, mNsfwAndSpoilerSharedPreferences,
|
||||
|
||||
@@ -398,8 +398,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
}
|
||||
};
|
||||
|
||||
mSwipeRefreshLayout.setEnabled(mSharedPreferences.getBoolean(SharedPreferencesUtils.PULL_TO_REFRESH, true));
|
||||
mSwipeRefreshLayout.setOnRefreshListener(this::refresh);
|
||||
|
||||
int recyclerViewPosition = 0;
|
||||
if (savedInstanceState != null) {
|
||||
@@ -437,6 +435,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
|
||||
postType = getArguments().getInt(EXTRA_POST_TYPE);
|
||||
|
||||
mSwipeRefreshLayout.setEnabled(mSharedPreferences.getBoolean(SharedPreferencesUtils.PULL_TO_REFRESH, true) && postType != PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE);
|
||||
mSwipeRefreshLayout.setOnRefreshListener(this::refresh);
|
||||
|
||||
accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
|
||||
accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
|
||||
int defaultPostLayout = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY, "0"));
|
||||
@@ -725,6 +726,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
}
|
||||
});
|
||||
} else if (postType == PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE) {
|
||||
subredditName = getArguments().getString(EXTRA_NAME);
|
||||
usage = PostFilterUsage.HOME_TYPE;
|
||||
nameOfUsage = PostFilterUsage.NO_USAGE;
|
||||
subredditName = getArguments().getString(EXTRA_NAME);
|
||||
@@ -971,11 +973,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
this.postFilter = postFilter;
|
||||
postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false);
|
||||
this.concatenatedSubredditNames = concatenatedSubredditNames;
|
||||
if (concatenatedSubredditNames == null) {
|
||||
showErrorView(R.string.anonymous_front_page_no_subscriptions);
|
||||
} else {
|
||||
initializeAndBindPostViewModelForAnonymous(concatenatedSubredditNames);
|
||||
}
|
||||
showErrorView(R.string.anonymous_homepage_not_implemented);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -1017,11 +1015,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
if (activity != null && !activity.isFinishing() && !activity.isDestroyed() && !isDetached()) {
|
||||
postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false);
|
||||
this.concatenatedSubredditNames = concatenatedSubredditNames;
|
||||
if (concatenatedSubredditNames == null) {
|
||||
showErrorView(R.string.anonymous_front_page_no_subscriptions);
|
||||
} else {
|
||||
initializeAndBindPostViewModelForAnonymous(concatenatedSubredditNames);
|
||||
}
|
||||
showErrorView(R.string.anonymous_homepage_not_implemented);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -1209,33 +1203,33 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
private void initializeAndBindPostViewModel(String accessToken) {
|
||||
if (postType == PostPagingSource.TYPE_SEARCH) {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||
mRetrofit.getRetrofit() , accessToken,
|
||||
mRetrofit, accessToken,
|
||||
accountName, mSharedPreferences,
|
||||
mPostFeedScrolledPositionSharedPreferences, mPostHistorySharedPreferences, subredditName,
|
||||
query, trendingSource, postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
|
||||
} else if (postType == PostPagingSource.TYPE_SUBREDDIT) {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||
mRetrofit.getRetrofit() , accessToken,
|
||||
mRetrofit, accessToken,
|
||||
accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
|
||||
mPostHistorySharedPreferences, subredditName, postType, sortType, postFilter, readPosts))
|
||||
.get(PostViewModel.class);
|
||||
} else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||
mRetrofit.getRetrofit(), accessToken,
|
||||
mRetrofit, accessToken,
|
||||
accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
|
||||
mPostHistorySharedPreferences, multiRedditPath, postType, sortType, postFilter, readPosts))
|
||||
.get(PostViewModel.class);
|
||||
} else if (postType == PostPagingSource.TYPE_USER) {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||
mRetrofit.getRetrofit(), accessToken,
|
||||
mRetrofit, accessToken,
|
||||
accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
|
||||
mPostHistorySharedPreferences, username, postType, sortType, postFilter, where, readPosts))
|
||||
.get(PostViewModel.class);
|
||||
} else {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||
mRetrofit.getRetrofit(), accessToken,
|
||||
mRetrofit, accessToken,
|
||||
accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
|
||||
mPostHistorySharedPreferences, postType, sortType, postFilter, readPosts,subredditName)).get(PostViewModel.class);
|
||||
mPostHistorySharedPreferences, postType, sortType, postFilter, readPosts, subredditName)).get(PostViewModel.class);
|
||||
}
|
||||
|
||||
bindPostViewModel();
|
||||
@@ -1245,28 +1239,28 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
//For anonymous user
|
||||
if (postType == PostPagingSource.TYPE_SEARCH) {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||
mRetrofit.getRetrofit(), null, accountName, mSharedPreferences,
|
||||
mRetrofit, null, accountName, mSharedPreferences,
|
||||
mPostFeedScrolledPositionSharedPreferences, null, subredditName, query, trendingSource,
|
||||
postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
|
||||
} else if (postType == PostPagingSource.TYPE_SUBREDDIT) {
|
||||
mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(mExecutor,
|
||||
mRetrofit.getRetrofit(), null, accountName, mSharedPreferences,
|
||||
mRetrofit, null, accountName, mSharedPreferences,
|
||||
mPostFeedScrolledPositionSharedPreferences, null, subredditName, postType, sortType,
|
||||
postFilter, readPosts)).get(PostViewModel.class);
|
||||
} else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||
mRetrofit.getRetrofit(), null, accountName, mSharedPreferences,
|
||||
mRetrofit, null, accountName, mSharedPreferences,
|
||||
mPostFeedScrolledPositionSharedPreferences, null, multiRedditPath,
|
||||
postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
|
||||
} else if (postType == PostPagingSource.TYPE_USER) {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||
mRetrofit.getRetrofit(), null, accountName, mSharedPreferences,
|
||||
mRetrofit, null, accountName, mSharedPreferences,
|
||||
mPostFeedScrolledPositionSharedPreferences, null, username, postType, sortType, postFilter,
|
||||
where, readPosts)).get(PostViewModel.class);
|
||||
} else {
|
||||
//Anonymous Front Page
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||
mRetrofit.getRetrofit(), mSharedPreferences, concatenatedSubredditNames, postType, sortType, postFilter,subredditName))
|
||||
mRetrofit, mSharedPreferences, concatenatedSubredditNames, postType, sortType, postFilter, subredditName))
|
||||
.get(PostViewModel.class);
|
||||
}
|
||||
|
||||
@@ -1357,7 +1351,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
}
|
||||
|
||||
mFetchPostInfoLinearLayout.setOnClickListener(null);
|
||||
showErrorView(R.string.no_posts);
|
||||
if (accessToken != null) {
|
||||
showErrorView(R.string.no_posts);
|
||||
} else {
|
||||
showErrorView(R.string.anonymous_homepage_not_implemented);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void changeSortType(SortType sortType) {
|
||||
|
||||
@@ -194,7 +194,7 @@ public class SidebarFragment extends Fragment {
|
||||
|
||||
public void fetchSubredditData() {
|
||||
swipeRefreshLayout.setRefreshing(true);
|
||||
FetchSubredditData.fetchSubredditData(mOauthRetrofit, mRetrofit.getRetrofit(), communityQualifiedName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
FetchSubredditData.fetchSubredditData(mRetrofit.getRetrofit(), communityQualifiedName, mAccessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
|
||||
@@ -48,6 +48,7 @@ import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditListingViewModel;
|
||||
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
|
||||
|
||||
@@ -149,13 +150,13 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subredditSelected(String subredditName, String communityFullName, String iconUrl) {
|
||||
public void subredditSelected(SubredditData communityData) {
|
||||
if (isGettingSubredditInfo) {
|
||||
((SearchSubredditsResultActivity) mActivity).getSelectedSubreddit(subredditName, iconUrl);
|
||||
((SearchSubredditsResultActivity) mActivity).getSelectedSubreddit(communityData);
|
||||
} else {
|
||||
Intent intent = new Intent(mActivity, ViewSubredditDetailActivity.class);
|
||||
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, subredditName);
|
||||
intent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityFullName);
|
||||
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, communityData.getName());
|
||||
intent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, LemmyUtils.actorID2FullName(communityData.getActorId()));
|
||||
mActivity.startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra
|
||||
if (getArguments().getBoolean(EXTRA_IS_SUBREDDIT_SELECTION)) {
|
||||
adapter = new SubscribedSubredditsRecyclerViewAdapter(mActivity, mExecutor, mOauthRetrofit, mRedditDataRoomDatabase,
|
||||
mCustomThemeWrapper, accessToken, getArguments().getBoolean(EXTRA_EXTRA_CLEAR_SELECTION),
|
||||
(name, iconUrl, subredditIsUser) -> ((SubredditSelectionActivity) mActivity).getSelectedSubreddit(name, iconUrl, subredditIsUser));
|
||||
(communityData) -> ((SubredditSelectionActivity) mActivity).getSelectedSubreddit(communityData));
|
||||
} else {
|
||||
adapter = new SubscribedSubredditsRecyclerViewAdapter(mActivity, mExecutor, mOauthRetrofit, mRedditDataRoomDatabase,
|
||||
mCustomThemeWrapper, accessToken);
|
||||
|
||||
@@ -73,6 +73,7 @@ import eu.toldi.infinityforlemmy.Infinity;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import eu.toldi.infinityforlemmy.SavePost;
|
||||
import eu.toldi.infinityforlemmy.SaveThing;
|
||||
import eu.toldi.infinityforlemmy.SortType;
|
||||
import eu.toldi.infinityforlemmy.activities.CommentActivity;
|
||||
@@ -84,7 +85,6 @@ import eu.toldi.infinityforlemmy.activities.SubmitCrosspostActivity;
|
||||
import eu.toldi.infinityforlemmy.activities.ViewPostDetailActivity;
|
||||
import eu.toldi.infinityforlemmy.adapters.CommentsRecyclerViewAdapter;
|
||||
import eu.toldi.infinityforlemmy.adapters.PostDetailRecyclerViewAdapter;
|
||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
||||
import eu.toldi.infinityforlemmy.apis.StreamableAPI;
|
||||
import eu.toldi.infinityforlemmy.asynctasks.LoadUserData;
|
||||
@@ -94,7 +94,6 @@ import eu.toldi.infinityforlemmy.comment.Comment;
|
||||
import eu.toldi.infinityforlemmy.comment.FetchComment;
|
||||
import eu.toldi.infinityforlemmy.comment.FetchRemovedComment;
|
||||
import eu.toldi.infinityforlemmy.comment.FetchRemovedCommentReveddit;
|
||||
import eu.toldi.infinityforlemmy.comment.ParseComment;
|
||||
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.customviews.CustomToroContainer;
|
||||
import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
|
||||
@@ -108,7 +107,6 @@ import eu.toldi.infinityforlemmy.message.ReadMessage;
|
||||
import eu.toldi.infinityforlemmy.post.FetchPost;
|
||||
import eu.toldi.infinityforlemmy.post.FetchRemovedPost;
|
||||
import eu.toldi.infinityforlemmy.post.HidePost;
|
||||
import eu.toldi.infinityforlemmy.post.ParsePost;
|
||||
import eu.toldi.infinityforlemmy.post.Post;
|
||||
import eu.toldi.infinityforlemmy.readpost.InsertReadPost;
|
||||
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
|
||||
@@ -545,11 +543,11 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
}
|
||||
};
|
||||
|
||||
mSingleCommentId = (getArguments().getString(EXTRA_SINGLE_COMMENT_ID) == null) ? null : Integer.valueOf(getArguments().getString(EXTRA_SINGLE_COMMENT_ID));
|
||||
mSingleCommentId = getArguments().getInt(EXTRA_SINGLE_COMMENT_ID, 0);
|
||||
mContextNumber = getArguments().getString(EXTRA_CONTEXT_NUMBER, "8");
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
if (mSingleCommentId != null) {
|
||||
if (mSingleCommentId != 0) {
|
||||
isSingleCommentThreadMode = true;
|
||||
}
|
||||
mMessageFullname = getArguments().getString(EXTRA_MESSAGE_FULLNAME);
|
||||
@@ -593,7 +591,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
}
|
||||
|
||||
if (mPost == null) {
|
||||
fetchPostAndCommentsById(getArguments().getString(EXTRA_POST_ID));
|
||||
fetchPostAndCommentsById(getArguments().getInt(EXTRA_POST_ID));
|
||||
} else {
|
||||
setupMenu();
|
||||
|
||||
@@ -948,9 +946,10 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
return true;
|
||||
} else if (itemId == R.id.action_save_view_post_detail_fragment) {
|
||||
if (mPost != null && mAccessToken != null) {
|
||||
SavePost savePost = new SavePost();
|
||||
if (mPost.isSaved()) {
|
||||
item.setIcon(mUnsavedIcon);
|
||||
SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, mPost.getFullName(),
|
||||
savePost.unsaveThing(mOauthRetrofit, mAccessToken, mPost.getId(),
|
||||
new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
@@ -974,7 +973,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
});
|
||||
} else {
|
||||
item.setIcon(mSavedIcon);
|
||||
SaveThing.saveThing(mOauthRetrofit, mAccessToken, mPost.getFullName(),
|
||||
savePost.saveThing(mOauthRetrofit, mAccessToken, mPost.getId(),
|
||||
new SaveThing.SaveThingListener() {
|
||||
@Override
|
||||
public void success() {
|
||||
@@ -1238,153 +1237,91 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
return true;
|
||||
}
|
||||
|
||||
private void fetchPostAndCommentsById(String subredditId) {
|
||||
private void fetchPostAndCommentsById(int subredditId) {
|
||||
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
|
||||
mSwipeRefreshLayout.setRefreshing(true);
|
||||
mGlide.clear(mFetchPostInfoImageView);
|
||||
|
||||
Call<String> postAndComments = mRetrofit.getRetrofit().create(LemmyAPI.class).getComments("All", sortType.value, 5, 1, 25, null, null, Integer.valueOf(subredditId), mSingleCommentId, false, mAccessToken);
|
||||
postAndComments.enqueue(new Callback<>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (!isAdded()) {
|
||||
return;
|
||||
}
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
|
||||
if (response.isSuccessful()) {
|
||||
ParsePost.parsePost(mExecutor, new Handler(), response.body(), new ParsePost.ParsePostListener() {
|
||||
@Override
|
||||
public void onParsePostSuccess(Post post) {
|
||||
mPost = post;
|
||||
tryMarkingPostAsRead();
|
||||
|
||||
setupMenu();
|
||||
|
||||
mPostAdapter = new PostDetailRecyclerViewAdapter(activity,
|
||||
ViewPostDetailFragment.this, mExecutor, mCustomThemeWrapper,
|
||||
mRetrofit.getRetrofit(), mOauthRetrofit, mGfycatRetrofit, mRedgifsRetrofit,
|
||||
mStreamableApiProvider, mRedditDataRoomDatabase, mGlide, mSeparatePostAndComments,
|
||||
mAccessToken, mAccountName, mPost, mLocale, mSharedPreferences,
|
||||
mCurrentAccountSharedPreferences, mNsfwAndSpoilerSharedPreferences,
|
||||
mPostDetailsSharedPreferences, mExoCreator,
|
||||
post1 -> EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)));
|
||||
|
||||
mCommentsAdapter = new CommentsRecyclerViewAdapter(activity,
|
||||
ViewPostDetailFragment.this, mCustomThemeWrapper, mExecutor,
|
||||
mRetrofit.getRetrofit(), mOauthRetrofit, mAccessToken, mAccountName, mPost, mLocale,
|
||||
mSingleCommentId, isSingleCommentThreadMode, mSharedPreferences,
|
||||
new CommentsRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
|
||||
@Override
|
||||
public void retryFetchingComments() {
|
||||
fetchCommentsRespectRecommendedSort(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void retryFetchingMoreComments() {
|
||||
isLoadingMoreChildren = false;
|
||||
loadMoreChildrenSuccess = true;
|
||||
|
||||
fetchMoreComments();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortType.Type getSortType() {
|
||||
return sortType;
|
||||
}
|
||||
});
|
||||
if (mCommentsRecyclerView != null) {
|
||||
mRecyclerView.setAdapter(mPostAdapter);
|
||||
mCommentsRecyclerView.setAdapter(mCommentsAdapter);
|
||||
} else {
|
||||
mConcatAdapter = new ConcatAdapter(mPostAdapter, mCommentsAdapter);
|
||||
mRecyclerView.setAdapter(mConcatAdapter);
|
||||
}
|
||||
|
||||
if (mRespectSubredditRecommendedSortType) {
|
||||
fetchCommentsRespectRecommendedSort(false);
|
||||
} else {
|
||||
ParseComment.parseComments(mExecutor, new Handler(), response.body(), null,
|
||||
mExpandChildren, new ParseComment.ParseCommentListener() {
|
||||
FetchPost.fetchPost(mExecutor, new Handler(), mRetrofit.getRetrofit(), String.valueOf(subredditId), mAccessToken,
|
||||
new FetchPost.FetchPostListener() {
|
||||
@Override
|
||||
public void fetchPostSuccess(Post post) {
|
||||
if (!isAdded()) {
|
||||
return;
|
||||
}
|
||||
mPost = post;
|
||||
mPostAdapter = new PostDetailRecyclerViewAdapter(activity,
|
||||
ViewPostDetailFragment.this, mExecutor, mCustomThemeWrapper,
|
||||
mRetrofit.getRetrofit(), mOauthRetrofit, mGfycatRetrofit, mRedgifsRetrofit,
|
||||
mStreamableApiProvider, mRedditDataRoomDatabase, mGlide, mSeparatePostAndComments,
|
||||
mAccessToken, mAccountName, mPost, mLocale, mSharedPreferences,
|
||||
mCurrentAccountSharedPreferences, mNsfwAndSpoilerSharedPreferences,
|
||||
mPostDetailsSharedPreferences, mExoCreator,
|
||||
post1 -> EventBus.getDefault().post(new PostUpdateEventToPostList(mPost, postListPosition)));
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
FetchComment.fetchComments(mExecutor, new Handler(), mRetrofit.getRetrofit(), mAccessToken, subredditId, mSingleCommentId, sortType, mExpandChildren, 1, new FetchComment.FetchCommentListener() {
|
||||
@Override
|
||||
public void onFetchCommentSuccess(ArrayList<Comment> expandedComments, Integer parentId, ArrayList<Integer> children) {
|
||||
pages_loaded++;
|
||||
mCommentsAdapter = new CommentsRecyclerViewAdapter(activity,
|
||||
ViewPostDetailFragment.this, mCustomThemeWrapper, mExecutor,
|
||||
mRetrofit.getRetrofit(), mOauthRetrofit, mAccessToken, mAccountName, mPost, mLocale,
|
||||
mSingleCommentId, isSingleCommentThreadMode, mSharedPreferences,
|
||||
new CommentsRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
|
||||
@Override
|
||||
public void onParseCommentSuccess(ArrayList<Comment> topLevelComments, ArrayList<Comment> expandedComments, Integer parentId, ArrayList<Integer> moreChildrenIds) {
|
||||
ViewPostDetailFragment.this.children = moreChildrenIds;
|
||||
|
||||
hasMoreChildren = children.size() != 0;
|
||||
mCommentsAdapter.addComments(expandedComments, hasMoreChildren);
|
||||
|
||||
if (children.size() > 0) {
|
||||
(mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).clearOnScrollListeners();
|
||||
(mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
||||
super.onScrolled(recyclerView, dx, dy);
|
||||
if (!mIsSmoothScrolling && !mLockFab) {
|
||||
if (!recyclerView.canScrollVertically(1)) {
|
||||
activity.hideFab();
|
||||
} else {
|
||||
if (dy > 0) {
|
||||
if (mSwipeUpToHideFab) {
|
||||
activity.showFab();
|
||||
} else {
|
||||
activity.hideFab();
|
||||
}
|
||||
} else {
|
||||
if (mSwipeUpToHideFab) {
|
||||
activity.hideFab();
|
||||
} else {
|
||||
activity.showFab();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isLoadingMoreChildren && loadMoreChildrenSuccess) {
|
||||
int visibleItemCount = (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager().getChildCount();
|
||||
int totalItemCount = (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager().getItemCount();
|
||||
int firstVisibleItemPosition = ((LinearLayoutManagerBugFixed) (mCommentsRecyclerView == null ? mRecyclerView : mCommentsRecyclerView).getLayoutManager()).findFirstVisibleItemPosition();
|
||||
|
||||
if ((visibleItemCount + firstVisibleItemPosition >= totalItemCount) && firstVisibleItemPosition >= 0) {
|
||||
fetchMoreComments();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
|
||||
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
||||
mIsSmoothScrolling = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
public void retryFetchingComments() {
|
||||
fetchCommentsRespectRecommendedSort(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onParseCommentFailed() {
|
||||
mCommentsAdapter.initiallyLoadCommentsFailed();
|
||||
public void retryFetchingMoreComments() {
|
||||
isLoadingMoreChildren = false;
|
||||
loadMoreChildrenSuccess = true;
|
||||
|
||||
fetchMoreComments();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortType.Type getSortType() {
|
||||
return sortType;
|
||||
}
|
||||
});
|
||||
if (mCommentsRecyclerView != null) {
|
||||
mRecyclerView.setAdapter(mPostAdapter);
|
||||
mCommentsRecyclerView.setAdapter(mCommentsAdapter);
|
||||
} else {
|
||||
mConcatAdapter = new ConcatAdapter(mPostAdapter, mCommentsAdapter);
|
||||
mRecyclerView.setAdapter(mConcatAdapter);
|
||||
}
|
||||
|
||||
if (mRespectSubredditRecommendedSortType) {
|
||||
fetchCommentsRespectRecommendedSort(false);
|
||||
}
|
||||
ViewPostDetailFragment.this.children = children;
|
||||
|
||||
hasMoreChildren = false;
|
||||
mCommentsAdapter.addComments(expandedComments, hasMoreChildren);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onParsePostFail() {
|
||||
showErrorView(subredditId);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
showErrorView(subredditId);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onFetchCommentFailed() {
|
||||
if (isAdded()) {
|
||||
showErrorView(subredditId);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fetchPostFailed() {
|
||||
if (isAdded()) {
|
||||
showMessage(R.string.refresh_post_failed);
|
||||
isRefreshing = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||
if (isAdded()) {
|
||||
showErrorView(subredditId);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void fetchCommentsRespectRecommendedSort(boolean changeRefreshState, SortType.Type sortType) {
|
||||
@@ -1400,22 +1337,17 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
FetchSubredditData.fetchSubredditData(mOauthRetrofit, mRetrofit.getRetrofit(), mPost.getSubredditNamePrefixed(), mAccessToken,
|
||||
FetchSubredditData.fetchSubredditData(mRetrofit.getRetrofit(), mPost.getSubredditNamePrefixed(), mAccessToken,
|
||||
new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
String suggestedCommentSort = "top";
|
||||
SortType.Type sortTypeType;
|
||||
if (suggestedCommentSort == null || suggestedCommentSort.equals("null") || suggestedCommentSort.equals("")) {
|
||||
mRespectSubredditRecommendedSortType = false;
|
||||
try {
|
||||
sortTypeType = SortType.Type.fromValue(suggestedCommentSort);
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
sortTypeType = loadSortType();
|
||||
} else {
|
||||
try {
|
||||
sortTypeType = SortType.Type.valueOf(suggestedCommentSort.toUpperCase(Locale.US));
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
sortTypeType = loadSortType();
|
||||
}
|
||||
}
|
||||
activity.setTitle(sortTypeType.fullName);
|
||||
ViewPostDetailFragment.this.sortType = sortTypeType;
|
||||
@@ -1450,6 +1382,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
@Override
|
||||
public void onFetchCommentSuccess(ArrayList<Comment> expandedComments,
|
||||
Integer parentId, ArrayList<Integer> children) {
|
||||
isFetchingComments = false;
|
||||
ViewPostDetailFragment.this.children = children;
|
||||
pages_loaded++;
|
||||
comments = expandedComments;
|
||||
@@ -1508,8 +1441,6 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
if (changeRefreshState) {
|
||||
isRefreshing = false;
|
||||
}
|
||||
|
||||
isFetchingComments = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1535,8 +1466,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
|
||||
isLoadingMoreChildren = true;
|
||||
|
||||
Retrofit retrofit = mAccessToken == null ? mRetrofit.getRetrofit() : mOauthRetrofit;
|
||||
FetchComment.fetchComments(mExecutor, new Handler(), retrofit, mAccessToken,
|
||||
FetchComment.fetchComments(mExecutor, new Handler(), mRetrofit.getRetrofit(), mAccessToken,
|
||||
mPost.getId(), null, sortType, mExpandChildren, pages_loaded + 1, new FetchComment.FetchCommentListener() {
|
||||
@Override
|
||||
public void onFetchCommentSuccess(ArrayList<Comment> expandedComments, Integer parentId, ArrayList<Integer> children) {
|
||||
@@ -1582,6 +1512,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
|
||||
if (fetchComments) {
|
||||
pages_loaded = 0;
|
||||
mCommentsAdapter.clearLoadedComments();
|
||||
fetchCommentsRespectRecommendedSort(true);
|
||||
} else {
|
||||
isRefreshing = false;
|
||||
@@ -1601,7 +1533,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
}
|
||||
}
|
||||
|
||||
private void showErrorView(String subredditId) {
|
||||
private void showErrorView(int subredditId) {
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
mFetchPostInfoLinearLayout.setVisibility(View.VISIBLE);
|
||||
mFetchPostInfoLinearLayout.setOnClickListener(view -> fetchPostAndCommentsById(subredditId));
|
||||
|
||||
@@ -8,6 +8,11 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import org.commonmark.ext.gfm.tables.TableBlock;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.customviews.CustomMarkwonAdapter;
|
||||
import io.noties.markwon.Markwon;
|
||||
import io.noties.markwon.MarkwonPlugin;
|
||||
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
|
||||
@@ -20,8 +25,6 @@ import io.noties.markwon.recycler.MarkwonAdapter;
|
||||
import io.noties.markwon.recycler.table.TableEntry;
|
||||
import io.noties.markwon.recycler.table.TableEntryPlugin;
|
||||
import me.saket.bettermovementmethod.BetterLinkMovementMethod;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.customviews.CustomMarkwonAdapter;
|
||||
|
||||
public class MarkdownUtils {
|
||||
/**
|
||||
@@ -112,4 +115,39 @@ public class MarkdownUtils {
|
||||
.textLayoutIsRoot(R.layout.view_table_entry_cell)))
|
||||
.build();
|
||||
}
|
||||
|
||||
private static final Pattern emptyPattern = Pattern.compile("!\\[\\]\\((.*?)\\)");
|
||||
private static final Pattern nonEmptyPattern = Pattern.compile("!\\[(.*?)\\]\\((.*?)\\)");
|
||||
|
||||
public static String processImageCaptions(String markdown, String replacementCaption) {
|
||||
// Pattern for Markdown images with empty captions
|
||||
|
||||
// Pattern for Markdown images with non-empty captions
|
||||
|
||||
|
||||
Matcher emptyMatcher = emptyPattern.matcher(markdown);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
while (emptyMatcher.find()) {
|
||||
// Replace the matched pattern with the same URL, but with a caption
|
||||
emptyMatcher.appendReplacement(sb, "[" + replacementCaption + "](" + emptyMatcher.group(1) + ")");
|
||||
}
|
||||
|
||||
// Append the rest of the content
|
||||
emptyMatcher.appendTail(sb);
|
||||
|
||||
// Now process non-empty captions
|
||||
Matcher nonEmptyMatcher = nonEmptyPattern.matcher(sb.toString());
|
||||
StringBuffer finalSb = new StringBuffer();
|
||||
|
||||
while (nonEmptyMatcher.find()) {
|
||||
// Replace the matched pattern with the same URL and caption, but without the "!"
|
||||
nonEmptyMatcher.appendReplacement(finalSb, "[" + nonEmptyMatcher.group(1) + "](" + nonEmptyMatcher.group(2) + ")");
|
||||
}
|
||||
|
||||
// Append the rest of the content
|
||||
nonEmptyMatcher.appendTail(finalSb);
|
||||
|
||||
return finalSb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,17 +18,23 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import eu.toldi.infinityforlemmy.markdown.MarkdownUtils;
|
||||
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
|
||||
import eu.toldi.infinityforlemmy.utils.JSONUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
|
||||
@@ -152,15 +158,30 @@ public class ParsePost {
|
||||
String authorFull = LemmyUtils.actorID2FullName(creator.getString("actor_id"));
|
||||
long postTimeMillis = 0;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
postTimeMillis = ZonedDateTime.parse(post.getString("published"),
|
||||
postTimeMillis = ZonedDateTime.parse(post.getString("published"),
|
||||
DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneId.of("Z"))).toInstant().toEpochMilli();
|
||||
} else {
|
||||
String dateStr = post.getString("published");
|
||||
|
||||
dateStr = dateStr.substring(0, dateStr.lastIndexOf(".") + 4) + 'Z';
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault());
|
||||
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
try {
|
||||
Date date = sdf.parse(dateStr);
|
||||
if (date != null) {
|
||||
postTimeMillis = date.getTime();
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
String title = post.getString("name");
|
||||
String permalink = post.getString("ap_id");
|
||||
int score = counts.getInt("score");
|
||||
int voteType = 0;
|
||||
int nComments = counts.getInt("comments");
|
||||
int upvoteRatio = 100 * counts.getInt("upvotes") / max(counts.getInt("upvotes") + counts.getInt("downvotes"),1);
|
||||
int upvoteRatio = 100 * counts.getInt("upvotes") / max(counts.getInt("upvotes") + counts.getInt("downvotes"), 1);
|
||||
boolean hidden = community.getBoolean("hidden");
|
||||
boolean nsfw = post.getBoolean("nsfw");
|
||||
boolean locked = post.getBoolean("locked");
|
||||
@@ -501,8 +522,23 @@ public class ParsePost {
|
||||
post.setStreamableShortCode(shortCode);
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException ignore) { }
|
||||
} else if (post.getPostType() == Post.LINK_TYPE || post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
|
||||
} catch (IllegalArgumentException ignore) {
|
||||
}
|
||||
} else if (post.getPostType() == Post.TEXT_TYPE) {
|
||||
List<ImageInfo> images = extractImages(post.getSelfText());
|
||||
if (images.size() == 1) {
|
||||
post.setPostType(Post.IMAGE_TYPE);
|
||||
post.setUrl(images.get(0).imageUrl);
|
||||
} else if (images.size() > 1) {
|
||||
post.setPostType(Post.GALLERY_TYPE);
|
||||
ArrayList<Post.Gallery> gallery = new ArrayList<>();
|
||||
for (ImageInfo image : images) {
|
||||
String[] imagePath = image.getImageUrl().split(Pattern.quote("/"));
|
||||
gallery.add(new Post.Gallery("image/jpg", image.getImageUrl(), "", imagePath[imagePath.length - 1], image.caption, ""));
|
||||
}
|
||||
post.setGallery(gallery);
|
||||
}
|
||||
|
||||
if (!data.isNull(JSONUtils.GALLERY_DATA_KEY)) {
|
||||
JSONArray galleryIdsArray = data.getJSONObject(JSONUtils.GALLERY_DATA_KEY).getJSONArray(JSONUtils.ITEMS_KEY);
|
||||
JSONObject galleryObject = data.getJSONObject(JSONUtils.MEDIA_METADATA_KEY);
|
||||
@@ -612,17 +648,17 @@ public class ParsePost {
|
||||
}
|
||||
}
|
||||
}
|
||||
if(data.getBoolean("read")){
|
||||
if (data.getBoolean("read")) {
|
||||
post.markAsRead();
|
||||
}
|
||||
if(!data.isNull("my_vote")){
|
||||
if (!data.isNull("my_vote")) {
|
||||
post.setVoteType(data.getInt("my_vote"));
|
||||
post.setScore(post.getScore()-1);
|
||||
post.setScore(post.getScore() - 1);
|
||||
}
|
||||
|
||||
|
||||
if (!data.getJSONObject("post").isNull("body")) {
|
||||
String body = data.getJSONObject("post").getString("body");
|
||||
String body = MarkdownUtils.processImageCaptions(data.getJSONObject("post").getString("body"), "Image");
|
||||
post.setSelfText(body);
|
||||
post.setSelfTextPlain(body);
|
||||
post.setSelfTextPlainTrimmed(body.trim());
|
||||
@@ -674,4 +710,40 @@ public class ParsePost {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class ImageInfo {
|
||||
private String caption;
|
||||
private String imageUrl;
|
||||
|
||||
public ImageInfo(String caption, String imageUrl) {
|
||||
this.caption = caption;
|
||||
this.imageUrl = imageUrl;
|
||||
}
|
||||
|
||||
public String getCaption() {
|
||||
return caption;
|
||||
}
|
||||
|
||||
public String getImageUrl() {
|
||||
return imageUrl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static List<ImageInfo> extractImages(String markdown) {
|
||||
List<ImageInfo> images = new ArrayList<>();
|
||||
|
||||
// Regular expression to match markdown image syntax 
|
||||
Pattern pattern = Pattern.compile("!\\[(.*?)\\]\\((.*?)\\)");
|
||||
Matcher matcher = pattern.matcher(markdown);
|
||||
|
||||
// Find all matches and extract image URLs and captions
|
||||
while (matcher.find()) {
|
||||
String caption = matcher.group(1);
|
||||
String imageUrl = matcher.group(2);
|
||||
images.add(new ImageInfo(caption, imageUrl));
|
||||
}
|
||||
|
||||
return images;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import eu.toldi.infinityforlemmy.SortType;
|
||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import retrofit2.HttpException;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post> {
|
||||
public static final int TYPE_FRONT_PAGE = 0;
|
||||
@@ -43,7 +43,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
||||
public static final String USER_WHERE_GILDED = "gilded";
|
||||
|
||||
private Executor executor;
|
||||
private Retrofit retrofit;
|
||||
private RetrofitHolder retrofit;
|
||||
private String accessToken;
|
||||
private String accountName;
|
||||
private SharedPreferences sharedPreferences;
|
||||
@@ -61,10 +61,10 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
||||
|
||||
private int page = 1;
|
||||
|
||||
PostPagingSource(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
PostPagingSource(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences,
|
||||
SharedPreferences postFeedScrolledPositionSharedPreferences, int postType,
|
||||
SortType sortType, PostFilter postFilter, List<String> readPostList,String option) {
|
||||
SortType sortType, PostFilter postFilter, List<String> readPostList, String option) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
@@ -79,7 +79,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
||||
postLinkedHashSet = new LinkedHashSet<>();
|
||||
}
|
||||
|
||||
PostPagingSource(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
PostPagingSource(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
String path, int postType, SortType sortType, PostFilter postFilter,
|
||||
List<String> readPostList) {
|
||||
@@ -117,7 +117,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
||||
postLinkedHashSet = new LinkedHashSet<>();
|
||||
}
|
||||
|
||||
PostPagingSource(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
PostPagingSource(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
String subredditOrUserName, int postType, SortType sortType, PostFilter postFilter,
|
||||
String where, List<String> readPostList) {
|
||||
@@ -136,7 +136,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
||||
postLinkedHashSet = new LinkedHashSet<>();
|
||||
}
|
||||
|
||||
PostPagingSource(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
PostPagingSource(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
String subredditOrUserName, String query, String trendingSource, int postType,
|
||||
SortType sortType, PostFilter postFilter, List<String> readPostList) {
|
||||
@@ -165,17 +165,21 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
||||
@NonNull
|
||||
@Override
|
||||
public ListenableFuture<LoadResult<Integer, Post>> loadFuture(@NonNull LoadParams<Integer> loadParams) {
|
||||
LemmyAPI api = retrofit.create(LemmyAPI.class);
|
||||
LemmyAPI api = retrofit.getRetrofit().create(LemmyAPI.class);
|
||||
switch (postType) {
|
||||
default:
|
||||
|
||||
case TYPE_FRONT_PAGE:
|
||||
return loadHomePosts(loadParams, api);
|
||||
case TYPE_SUBREDDIT:
|
||||
return loadSubredditPosts(loadParams, api);
|
||||
case TYPE_USER:
|
||||
return loadUserPosts(loadParams, api);
|
||||
case TYPE_SEARCH:
|
||||
return loadSearchPosts(loadParams, api);
|
||||
case TYPE_SUBREDDIT:
|
||||
return loadSubredditPosts(loadParams, api);
|
||||
default:
|
||||
case TYPE_ANONYMOUS_FRONT_PAGE:
|
||||
// Return a dummy result
|
||||
return Futures.immediateFuture(new LoadResult.Page<>(new ArrayList<>(), null, null));
|
||||
/* case TYPE_MULTI_REDDIT:
|
||||
return loadMultiRedditPosts(loadParams, api);
|
||||
default:
|
||||
@@ -191,9 +195,19 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
||||
if (newPosts == null) {
|
||||
return new LoadResult.Error<>(new Exception("Error parsing posts"));
|
||||
} else {
|
||||
List<Post> trulyNewPosts = new ArrayList<>();
|
||||
for (Post post : newPosts) {
|
||||
if (!postLinkedHashSet.contains(post)) {
|
||||
trulyNewPosts.add(post);
|
||||
}
|
||||
}
|
||||
int currentPostsSize = postLinkedHashSet.size();
|
||||
postLinkedHashSet.addAll(newPosts);
|
||||
int nextKey = (postLinkedHashSet.size()+1) / 25+1;
|
||||
postLinkedHashSet.addAll(trulyNewPosts);
|
||||
int nextKey = ++page;
|
||||
if (trulyNewPosts.size() == 0) {
|
||||
return new LoadResult.Page<>(new ArrayList<>(), null, null);
|
||||
}
|
||||
|
||||
if (currentPostsSize == postLinkedHashSet.size()) {
|
||||
return new LoadResult.Page<>(new ArrayList<>(), null, nextKey);
|
||||
} else {
|
||||
|
||||
@@ -21,14 +21,14 @@ import androidx.paging.PagingLiveData;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import eu.toldi.infinityforlemmy.SortType;
|
||||
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class PostViewModel extends ViewModel {
|
||||
private Executor executor;
|
||||
private Retrofit retrofit;
|
||||
private RetrofitHolder retrofit;
|
||||
private String accessToken;
|
||||
private String accountName;
|
||||
private SharedPreferences sharedPreferences;
|
||||
@@ -50,10 +50,10 @@ public class PostViewModel extends ViewModel {
|
||||
private MutableLiveData<PostFilter> postFilterLiveData;
|
||||
private SortTypeAndPostFilterLiveData sortTypeAndPostFilterLiveData;
|
||||
|
||||
public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
public PostViewModel(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
@Nullable SharedPreferences postHistorySharedPreferences, int postType,
|
||||
SortType sortType, PostFilter postFilter, List<String> readPostList,String option) {
|
||||
SortType sortType, PostFilter postFilter, List<String> readPostList, String option) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
this.accessToken = accessToken;
|
||||
@@ -92,7 +92,7 @@ public class PostViewModel extends ViewModel {
|
||||
&& postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false));
|
||||
}
|
||||
|
||||
public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
public PostViewModel(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
@Nullable SharedPreferences postHistorySharedPreferences, String subredditName, int postType,
|
||||
SortType sortType, PostFilter postFilter, List<String> readPostList) {
|
||||
@@ -134,7 +134,7 @@ public class PostViewModel extends ViewModel {
|
||||
&& postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false));
|
||||
}
|
||||
|
||||
public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
public PostViewModel(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences,
|
||||
SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
@Nullable SharedPreferences postHistorySharedPreferences, String username,
|
||||
@@ -179,7 +179,7 @@ public class PostViewModel extends ViewModel {
|
||||
&& postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false));
|
||||
}
|
||||
|
||||
public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
public PostViewModel(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
@Nullable SharedPreferences postHistorySharedPreferences, String subredditName, String query,
|
||||
String trendingSource, int postType, SortType sortType, PostFilter postFilter,
|
||||
@@ -277,7 +277,7 @@ public class PostViewModel extends ViewModel {
|
||||
|
||||
public static class Factory extends ViewModelProvider.NewInstanceFactory {
|
||||
private Executor executor;
|
||||
private Retrofit retrofit;
|
||||
private RetrofitHolder retrofit;
|
||||
private String accessToken;
|
||||
private String accountName;
|
||||
private SharedPreferences sharedPreferences;
|
||||
@@ -292,7 +292,7 @@ public class PostViewModel extends ViewModel {
|
||||
private String userWhere;
|
||||
private List<String> readPostList;
|
||||
|
||||
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
public Factory(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
SharedPreferences postHistorySharedPreferences, int postType, SortType sortType,
|
||||
PostFilter postFilter, List<String> readPostList, String option) {
|
||||
@@ -310,7 +310,7 @@ public class PostViewModel extends ViewModel {
|
||||
this.name = option;
|
||||
}
|
||||
|
||||
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
public Factory(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
SharedPreferences postHistorySharedPreferences, String name, int postType, SortType sortType,
|
||||
PostFilter postFilter, List<String> readPostList) {
|
||||
@@ -329,7 +329,7 @@ public class PostViewModel extends ViewModel {
|
||||
}
|
||||
|
||||
//User posts
|
||||
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
public Factory(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
SharedPreferences postHistorySharedPreferences, String username, int postType,
|
||||
SortType sortType, PostFilter postFilter, String where, List<String> readPostList) {
|
||||
@@ -348,7 +348,7 @@ public class PostViewModel extends ViewModel {
|
||||
this.readPostList = readPostList;
|
||||
}
|
||||
|
||||
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
|
||||
public Factory(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
SharedPreferences postHistorySharedPreferences, String name, String query, String trendingSource,
|
||||
int postType, SortType sortType, PostFilter postFilter, List<String> readPostList) {
|
||||
@@ -369,7 +369,7 @@ public class PostViewModel extends ViewModel {
|
||||
}
|
||||
|
||||
//Anonymous Front Page
|
||||
public Factory(Executor executor, Retrofit retrofit, SharedPreferences sharedPreferences,
|
||||
public Factory(Executor executor, RetrofitHolder retrofit, SharedPreferences sharedPreferences,
|
||||
String concatenatedSubredditNames, int postType, SortType sortType, PostFilter postFilter, String opt) {
|
||||
this.executor = executor;
|
||||
this.retrofit = retrofit;
|
||||
|
||||
@@ -5,49 +5,42 @@ import android.os.Handler;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import eu.toldi.infinityforlemmy.Flair;
|
||||
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||
import eu.toldi.infinityforlemmy.dto.SubmitPostDTO;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.JSONUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.UploadImageUtils;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.RequestBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class SubmitPost {
|
||||
public static void submitTextOrLinkPost(Executor executor, Handler handler, Retrofit oauthRetrofit, String accessToken,
|
||||
String subredditName, String title, String content,
|
||||
int communityId, String title, String content,
|
||||
Flair flair, boolean isSpoiler, boolean isNSFW,
|
||||
boolean receivePostReplyNotifications, String kind,
|
||||
SubmitPostListener submitPostListener) {
|
||||
submitPost(executor, handler, oauthRetrofit, accessToken, subredditName, title, content,
|
||||
submitPost(executor, handler, oauthRetrofit, accessToken, communityId, title, content,
|
||||
flair, isSpoiler, isNSFW, receivePostReplyNotifications, kind, null, submitPostListener);
|
||||
}
|
||||
|
||||
public static void submitImagePost(Executor executor, Handler handler, Retrofit oauthRetrofit, Retrofit uploadMediaRetrofit,
|
||||
String accessToken, String subredditName, String title, Bitmap image,
|
||||
public static void submitImagePost(Executor executor, Handler handler, RetrofitHolder mRetrofit,
|
||||
String accessToken, int communityId, String title, Bitmap image,
|
||||
Flair flair, boolean isSpoiler, boolean isNSFW,
|
||||
boolean receivePostReplyNotifications, SubmitPostListener submitPostListener) {
|
||||
try {
|
||||
String imageUrlOrError = UploadImageUtils.uploadImage(oauthRetrofit, uploadMediaRetrofit, accessToken, image);
|
||||
String imageUrlOrError = UploadImageUtils.uploadImage(mRetrofit, accessToken, image);
|
||||
if (imageUrlOrError != null && !imageUrlOrError.startsWith("Error: ")) {
|
||||
submitPost(executor, handler, oauthRetrofit, accessToken,
|
||||
subredditName, title, imageUrlOrError, flair, isSpoiler, isNSFW,
|
||||
receivePostReplyNotifications, APIUtils.KIND_IMAGE, null, submitPostListener);
|
||||
submitPost(executor, handler, mRetrofit.getRetrofit(), accessToken,
|
||||
communityId, title, null, flair, isSpoiler, isNSFW,
|
||||
receivePostReplyNotifications, APIUtils.KIND_IMAGE, imageUrlOrError, submitPostListener);
|
||||
} else {
|
||||
submitPostListener.submitFailed(imageUrlOrError);
|
||||
}
|
||||
@@ -57,122 +50,24 @@ public class SubmitPost {
|
||||
}
|
||||
}
|
||||
|
||||
public static void submitVideoPost(Executor executor, Handler handler, Retrofit oauthRetrofit, Retrofit uploadMediaRetrofit,
|
||||
Retrofit uploadVideoRetrofit, String accessToken,
|
||||
String subredditName, String title, File buffer, String mimeType,
|
||||
Bitmap posterBitmap, Flair flair, boolean isSpoiler, boolean isNSFW,
|
||||
boolean receivePostReplyNotifications, SubmitPostListener submitPostListener) {
|
||||
RedditAPI api = oauthRetrofit.create(RedditAPI.class);
|
||||
|
||||
String fileType = mimeType.substring(mimeType.indexOf("/") + 1);
|
||||
|
||||
Map<String, String> uploadImageParams = new HashMap<>();
|
||||
uploadImageParams.put(APIUtils.FILEPATH_KEY, "post_video." + fileType);
|
||||
uploadImageParams.put(APIUtils.MIMETYPE_KEY, mimeType);
|
||||
|
||||
Call<String> uploadImageCall = api.uploadImage(APIUtils.getOAuthHeader(accessToken), uploadImageParams);
|
||||
try {
|
||||
Response<String> uploadImageResponse = uploadImageCall.execute();
|
||||
if (uploadImageResponse.isSuccessful()) {
|
||||
Map<String, RequestBody> nameValuePairsMap = UploadImageUtils.parseJSONResponseFromAWS(uploadImageResponse.body());
|
||||
|
||||
RequestBody fileBody = RequestBody.create(buffer, MediaType.parse("application/octet-stream"));
|
||||
MultipartBody.Part fileToUpload = MultipartBody.Part.createFormData("file", "post_video." + fileType, fileBody);
|
||||
|
||||
RedditAPI uploadVideoToAWSApi;
|
||||
if (fileType.equals("gif")) {
|
||||
uploadVideoToAWSApi = uploadMediaRetrofit.create(RedditAPI.class);
|
||||
} else {
|
||||
uploadVideoToAWSApi = uploadVideoRetrofit.create(RedditAPI.class);
|
||||
}
|
||||
Call<String> uploadMediaToAWS = uploadVideoToAWSApi.uploadMediaToAWS(nameValuePairsMap, fileToUpload);
|
||||
Response<String> uploadMediaToAWSResponse = uploadMediaToAWS.execute();
|
||||
if (uploadMediaToAWSResponse.isSuccessful()) {
|
||||
String url = UploadImageUtils.parseXMLResponseFromAWS(uploadMediaToAWSResponse.body());
|
||||
if (url == null) {
|
||||
submitPostListener.submitFailed(null);
|
||||
return;
|
||||
}
|
||||
String imageUrlOrError = UploadImageUtils.uploadImage(oauthRetrofit, uploadMediaRetrofit, accessToken, posterBitmap);
|
||||
if (imageUrlOrError != null && !imageUrlOrError.startsWith("Error: ")) {
|
||||
if (fileType.equals("gif")) {
|
||||
submitPost(executor, handler, oauthRetrofit, accessToken,
|
||||
subredditName, title, url, flair, isSpoiler, isNSFW,
|
||||
receivePostReplyNotifications, APIUtils.KIND_VIDEOGIF, imageUrlOrError,
|
||||
submitPostListener);
|
||||
} else {
|
||||
submitPost(executor, handler, oauthRetrofit, accessToken,
|
||||
subredditName, title, url, flair, isSpoiler, isNSFW,
|
||||
receivePostReplyNotifications, APIUtils.KIND_VIDEO, imageUrlOrError,
|
||||
submitPostListener);
|
||||
}
|
||||
} else {
|
||||
submitPostListener.submitFailed(imageUrlOrError);
|
||||
}
|
||||
} else {
|
||||
submitPostListener.submitFailed(uploadMediaToAWSResponse.code() + " " + uploadMediaToAWSResponse.message());
|
||||
}
|
||||
} else {
|
||||
submitPostListener.submitFailed(uploadImageResponse.code() + " " + uploadImageResponse.message());
|
||||
}
|
||||
} catch (IOException | XmlPullParserException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
submitPostListener.submitFailed(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void submitCrosspost(Executor executor, Handler handler, Retrofit oauthRetrofit, String accessToken,
|
||||
String subredditName, String title, String crosspostFullname,
|
||||
int communityId, String title, String crosspostFullname,
|
||||
Flair flair, boolean isSpoiler, boolean isNSFW,
|
||||
boolean receivePostReplyNotifications, String kind,
|
||||
SubmitPostListener submitPostListener) {
|
||||
submitPost(executor, handler, oauthRetrofit, accessToken, subredditName, title, crosspostFullname,
|
||||
submitPost(executor, handler, oauthRetrofit, accessToken, communityId, title, crosspostFullname,
|
||||
flair, isSpoiler, isNSFW, receivePostReplyNotifications, kind, null, submitPostListener);
|
||||
}
|
||||
|
||||
private static void submitPost(Executor executor, Handler handler, Retrofit oauthRetrofit, String accessToken,
|
||||
String subredditName, String title, String content,
|
||||
int communityId, String title, String content,
|
||||
Flair flair, boolean isSpoiler, boolean isNSFW,
|
||||
boolean receivePostReplyNotifications, String kind,
|
||||
@Nullable String posterUrl, SubmitPostListener submitPostListener) {
|
||||
RedditAPI api = oauthRetrofit.create(RedditAPI.class);
|
||||
LemmyAPI api = oauthRetrofit.create(LemmyAPI.class);
|
||||
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put(APIUtils.API_TYPE_KEY, APIUtils.API_TYPE_JSON);
|
||||
params.put(APIUtils.SR_KEY, subredditName);
|
||||
params.put(APIUtils.TITLE_KEY, title);
|
||||
params.put(APIUtils.KIND_KEY, kind);
|
||||
switch (kind) {
|
||||
case APIUtils.KIND_SELF:
|
||||
params.put(APIUtils.TEXT_KEY, content);
|
||||
break;
|
||||
case APIUtils.KIND_LINK:
|
||||
case APIUtils.KIND_IMAGE:
|
||||
params.put(APIUtils.URL_KEY, content);
|
||||
break;
|
||||
case APIUtils.KIND_VIDEOGIF:
|
||||
params.put(APIUtils.KIND_KEY, APIUtils.KIND_IMAGE);
|
||||
params.put(APIUtils.URL_KEY, content);
|
||||
params.put(APIUtils.VIDEO_POSTER_URL_KEY, posterUrl);
|
||||
break;
|
||||
case APIUtils.KIND_VIDEO:
|
||||
params.put(APIUtils.URL_KEY, content);
|
||||
params.put(APIUtils.VIDEO_POSTER_URL_KEY, posterUrl);
|
||||
break;
|
||||
case APIUtils.KIND_CROSSPOST:
|
||||
params.put(APIUtils.CROSSPOST_FULLNAME_KEY, content);
|
||||
break;
|
||||
}
|
||||
|
||||
if (flair != null) {
|
||||
params.put(APIUtils.FLAIR_TEXT_KEY, flair.getText());
|
||||
params.put(APIUtils.FLAIR_ID_KEY, flair.getId());
|
||||
}
|
||||
params.put(APIUtils.SPOILER_KEY, Boolean.toString(isSpoiler));
|
||||
params.put(APIUtils.NSFW_KEY, Boolean.toString(isNSFW));
|
||||
params.put(APIUtils.SEND_REPLIES_KEY, Boolean.toString(receivePostReplyNotifications));
|
||||
|
||||
Call<String> submitPostCall = api.submit(APIUtils.getOAuthHeader(accessToken), params);
|
||||
Call<String> submitPostCall = api.postCreate(new SubmitPostDTO(title, communityId, posterUrl, content, null, isNSFW, null, accessToken));
|
||||
|
||||
try {
|
||||
Response<String> response = submitPostCall.execute();
|
||||
@@ -191,50 +86,18 @@ public class SubmitPost {
|
||||
private static void getSubmittedPost(Executor executor, Handler handler, String response, String kind,
|
||||
Retrofit oauthRetrofit, String accessToken,
|
||||
SubmitPostListener submitPostListener) throws JSONException, IOException {
|
||||
JSONObject responseObject = new JSONObject(response).getJSONObject(JSONUtils.JSON_KEY);
|
||||
if (responseObject.getJSONArray(JSONUtils.ERRORS_KEY).length() != 0) {
|
||||
JSONArray error = responseObject.getJSONArray(JSONUtils.ERRORS_KEY)
|
||||
.getJSONArray(responseObject.getJSONArray(JSONUtils.ERRORS_KEY).length() - 1);
|
||||
if (error.length() != 0) {
|
||||
String errorString;
|
||||
if (error.length() >= 2) {
|
||||
errorString = error.getString(1);
|
||||
} else {
|
||||
errorString = error.getString(0);
|
||||
}
|
||||
submitPostListener.submitFailed(errorString);
|
||||
} else {
|
||||
|
||||
ParsePost.parsePost(executor, handler, response, new ParsePost.ParsePostListener() {
|
||||
@Override
|
||||
public void onParsePostSuccess(Post post) {
|
||||
submitPostListener.submitSuccessful(post);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onParsePostFail() {
|
||||
submitPostListener.submitFailed(null);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!kind.equals(APIUtils.KIND_IMAGE) && !kind.equals(APIUtils.KIND_VIDEO) && !kind.equals(APIUtils.KIND_VIDEOGIF)) {
|
||||
String postId = responseObject.getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.ID_KEY);
|
||||
|
||||
RedditAPI api = oauthRetrofit.create(RedditAPI.class);
|
||||
|
||||
Call<String> getPostCall = api.getPostOauth(postId, APIUtils.getOAuthHeader(accessToken));
|
||||
Response<String> getPostCallResponse = getPostCall.execute();
|
||||
if (getPostCallResponse.isSuccessful()) {
|
||||
ParsePost.parsePost(executor, handler, getPostCallResponse.body(), new ParsePost.ParsePostListener() {
|
||||
@Override
|
||||
public void onParsePostSuccess(Post post) {
|
||||
submitPostListener.submitSuccessful(post);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onParsePostFail() {
|
||||
submitPostListener.submitFailed(null);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
submitPostListener.submitFailed(getPostCallResponse.message());
|
||||
}
|
||||
} else {
|
||||
submitPostListener.submitSuccessful(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public interface SubmitPostListener {
|
||||
|
||||
@@ -28,7 +28,6 @@ import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -36,12 +35,10 @@ import java.io.OutputStream;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import eu.toldi.infinityforlemmy.AnyAccountAccessTokenAuthenticator;
|
||||
import eu.toldi.infinityforlemmy.Flair;
|
||||
import eu.toldi.infinityforlemmy.Infinity;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
@@ -55,14 +52,11 @@ import eu.toldi.infinityforlemmy.events.SubmitGalleryPostEvent;
|
||||
import eu.toldi.infinityforlemmy.events.SubmitImagePostEvent;
|
||||
import eu.toldi.infinityforlemmy.events.SubmitPollPostEvent;
|
||||
import eu.toldi.infinityforlemmy.events.SubmitTextOrLinkPostEvent;
|
||||
import eu.toldi.infinityforlemmy.events.SubmitVideoOrGifPostEvent;
|
||||
import eu.toldi.infinityforlemmy.post.Post;
|
||||
import eu.toldi.infinityforlemmy.post.SubmitPost;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.JSONUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.NotificationUtils;
|
||||
import okhttp3.ConnectionPool;
|
||||
import okhttp3.OkHttpClient;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
@@ -90,9 +84,7 @@ public class SubmitPostService extends Service {
|
||||
@Inject
|
||||
@Named("no_oauth")
|
||||
RetrofitHolder mRetrofit;
|
||||
@Inject
|
||||
@Named("oauth")
|
||||
Retrofit mOauthRetrofit;
|
||||
|
||||
@Inject
|
||||
@Named("upload_media")
|
||||
Retrofit mUploadMediaRetrofit;
|
||||
@@ -130,7 +122,7 @@ public class SubmitPostService extends Service {
|
||||
super.handleMessage(msg);
|
||||
Bundle bundle = msg.getData();
|
||||
Account account = bundle.getParcelable(EXTRA_ACCOUNT);
|
||||
String subredditName = bundle.getString(EXTRA_SUBREDDIT_NAME);
|
||||
int subredditName = bundle.getInt(EXTRA_SUBREDDIT_NAME);
|
||||
String title = bundle.getString(EXTRA_TITLE);
|
||||
Flair flair = bundle.getParcelable(EXTRA_FLAIR);
|
||||
boolean isSpoiler = bundle.getBoolean(EXTRA_IS_SPOILER, false);
|
||||
@@ -138,35 +130,24 @@ public class SubmitPostService extends Service {
|
||||
boolean receivePostReplyNotifications = bundle.getBoolean(EXTRA_RECEIVE_POST_REPLY_NOTIFICATIONS, true);
|
||||
int postType = bundle.getInt(EXTRA_POST_TYPE, EXTRA_POST_TEXT_OR_LINK);
|
||||
|
||||
Retrofit newAuthenticatorOauthRetrofit = mOauthRetrofit.newBuilder().client(new OkHttpClient.Builder().authenticator(new AnyAccountAccessTokenAuthenticator(mRetrofit.getRetrofit(), mRedditDataRoomDatabase, account, mCurrentAccountSharedPreferences))
|
||||
.connectTimeout(30, TimeUnit.SECONDS)
|
||||
.readTimeout(30, TimeUnit.SECONDS)
|
||||
.writeTimeout(30, TimeUnit.SECONDS)
|
||||
.connectionPool(new ConnectionPool(0, 1, TimeUnit.NANOSECONDS))
|
||||
.build())
|
||||
.build();
|
||||
|
||||
if (postType == EXTRA_POST_TEXT_OR_LINK) {
|
||||
String content = bundle.getString(EXTRA_CONTENT);
|
||||
String kind = bundle.getString(EXTRA_KIND);
|
||||
submitTextOrLinkPost(newAuthenticatorOauthRetrofit, account, subredditName, title, content, flair, isSpoiler, isNSFW,
|
||||
submitTextOrLinkPost(mRetrofit.getRetrofit(), account, subredditName, title, content, flair, isSpoiler, isNSFW,
|
||||
receivePostReplyNotifications, kind);
|
||||
} else if (postType == EXTRA_POST_TYPE_CROSSPOST) {
|
||||
String content = bundle.getString(EXTRA_CONTENT);
|
||||
submitCrosspost(mExecutor, handler, newAuthenticatorOauthRetrofit, account, subredditName, title, content,
|
||||
submitCrosspost(mExecutor, handler, mRetrofit.getRetrofit(), account, subredditName, title, content,
|
||||
flair, isSpoiler, isNSFW, receivePostReplyNotifications);
|
||||
} else if (postType == EXTRA_POST_TYPE_IMAGE) {
|
||||
Uri mediaUri = Uri.parse(bundle.getString(EXTRA_MEDIA_URI));
|
||||
submitImagePost(newAuthenticatorOauthRetrofit, account, mediaUri, subredditName, title, flair, isSpoiler, isNSFW,
|
||||
receivePostReplyNotifications);
|
||||
} else if (postType == EXTRA_POST_TYPE_VIDEO) {
|
||||
Uri mediaUri = Uri.parse(bundle.getString(EXTRA_MEDIA_URI));
|
||||
submitVideoPost(newAuthenticatorOauthRetrofit, account, mediaUri, subredditName, title, flair, isSpoiler, isNSFW,
|
||||
submitImagePost(mRetrofit, account, mediaUri, subredditName, title, flair, isSpoiler, isNSFW,
|
||||
receivePostReplyNotifications);
|
||||
} else if (postType == EXTRA_POST_TYPE_GALLERY) {
|
||||
submitGalleryPost(newAuthenticatorOauthRetrofit, account, bundle.getString(EXTRA_REDDIT_GALLERY_PAYLOAD));
|
||||
submitGalleryPost(mRetrofit.getRetrofit(), account, bundle.getString(EXTRA_REDDIT_GALLERY_PAYLOAD));
|
||||
} else {
|
||||
submitPollPost(newAuthenticatorOauthRetrofit, account, bundle.getString(EXTRA_POLL_PAYLOAD));
|
||||
submitPollPost(mRetrofit.getRetrofit(), account, bundle.getString(EXTRA_POLL_PAYLOAD));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -233,11 +214,11 @@ public class SubmitPostService extends Service {
|
||||
.build();
|
||||
}
|
||||
|
||||
private void submitTextOrLinkPost(Retrofit newAuthenticatorOauthRetrofit, Account selectedAccount, String subredditName, String title, String content,
|
||||
private void submitTextOrLinkPost(Retrofit newAuthenticatorOauthRetrofit, Account selectedAccount, int communityId, String title, String content,
|
||||
Flair flair, boolean isSpoiler, boolean isNSFW, boolean receivePostReplyNotifications,
|
||||
String kind) {
|
||||
SubmitPost.submitTextOrLinkPost(mExecutor, handler, newAuthenticatorOauthRetrofit, selectedAccount.getAccessToken(),
|
||||
subredditName, title, content, flair, isSpoiler,
|
||||
communityId, title, content, flair, isSpoiler,
|
||||
isNSFW, receivePostReplyNotifications, kind, new SubmitPost.SubmitPostListener() {
|
||||
@Override
|
||||
public void submitSuccessful(Post post) {
|
||||
@@ -256,10 +237,10 @@ public class SubmitPostService extends Service {
|
||||
}
|
||||
|
||||
private void submitCrosspost(Executor executor, Handler handler, Retrofit newAuthenticatorOauthRetrofit,
|
||||
Account selectedAccount, String subredditName,
|
||||
Account selectedAccount, int communityId,
|
||||
String title, String content, Flair flair, boolean isSpoiler, boolean isNSFW,
|
||||
boolean receivePostReplyNotifications) {
|
||||
SubmitPost.submitCrosspost(executor, handler, newAuthenticatorOauthRetrofit, selectedAccount.getAccessToken(), subredditName, title,
|
||||
SubmitPost.submitCrosspost(executor, handler, newAuthenticatorOauthRetrofit, selectedAccount.getAccessToken(), communityId, title,
|
||||
content, flair, isSpoiler, isNSFW, receivePostReplyNotifications, APIUtils.KIND_CROSSPOST,
|
||||
new SubmitPost.SubmitPostListener() {
|
||||
@Override
|
||||
@@ -278,17 +259,17 @@ public class SubmitPostService extends Service {
|
||||
});
|
||||
}
|
||||
|
||||
private void submitImagePost(Retrofit newAuthenticatorOauthRetrofit, Account selectedAccount, Uri mediaUri, String subredditName, String title,
|
||||
private void submitImagePost(RetrofitHolder newAuthenticatorOauthRetrofit, Account selectedAccount, Uri mediaUri, int communityId, String title,
|
||||
Flair flair, boolean isSpoiler, boolean isNSFW, boolean receivePostReplyNotifications) {
|
||||
try {
|
||||
Bitmap resource = Glide.with(this).asBitmap().load(mediaUri).submit().get();
|
||||
SubmitPost.submitImagePost(mExecutor, handler, newAuthenticatorOauthRetrofit, mUploadMediaRetrofit,
|
||||
selectedAccount.getAccessToken(), subredditName, title, resource, flair, isSpoiler, isNSFW, receivePostReplyNotifications,
|
||||
SubmitPost.submitImagePost(mExecutor, handler, newAuthenticatorOauthRetrofit,
|
||||
selectedAccount.getAccessToken(), communityId, title, resource, flair, isSpoiler, isNSFW, receivePostReplyNotifications,
|
||||
new SubmitPost.SubmitPostListener() {
|
||||
@Override
|
||||
public void submitSuccessful(Post post) {
|
||||
handler.post(() -> {
|
||||
EventBus.getDefault().post(new SubmitImagePostEvent(true, null));
|
||||
EventBus.getDefault().post(new SubmitImagePostEvent(true, null, post));
|
||||
Toast.makeText(SubmitPostService.this, R.string.image_is_processing, Toast.LENGTH_SHORT).show();
|
||||
});
|
||||
|
||||
@@ -297,73 +278,18 @@ public class SubmitPostService extends Service {
|
||||
|
||||
@Override
|
||||
public void submitFailed(@Nullable String errorMessage) {
|
||||
handler.post(() -> EventBus.getDefault().post(new SubmitImagePostEvent(false, errorMessage)));
|
||||
handler.post(() -> EventBus.getDefault().post(new SubmitImagePostEvent(false, errorMessage, null)));
|
||||
|
||||
stopService();
|
||||
}
|
||||
});
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
handler.post(() -> EventBus.getDefault().post(new SubmitImagePostEvent(false, getString(R.string.error_processing_image))));
|
||||
handler.post(() -> EventBus.getDefault().post(new SubmitImagePostEvent(false, getString(R.string.error_processing_image), null)));
|
||||
stopService();
|
||||
}
|
||||
}
|
||||
|
||||
private void submitVideoPost(Retrofit newAuthenticatorOauthRetrofit, Account selectedAccount, Uri mediaUri, String subredditName, String title,
|
||||
Flair flair, boolean isSpoiler, boolean isNSFW, boolean receivePostReplyNotifications) {
|
||||
try {
|
||||
InputStream in = getContentResolver().openInputStream(mediaUri);
|
||||
String type = getContentResolver().getType(mediaUri);
|
||||
String cacheFilePath;
|
||||
if (type != null && type.contains("gif")) {
|
||||
cacheFilePath = getExternalCacheDir() + "/" + mediaUri.getLastPathSegment() + ".gif";
|
||||
} else {
|
||||
cacheFilePath = getExternalCacheDir() + "/" + mediaUri.getLastPathSegment() + ".mp4";
|
||||
}
|
||||
|
||||
copyFileToCache(in, cacheFilePath);
|
||||
|
||||
Bitmap resource = Glide.with(this).asBitmap().load(mediaUri).submit().get();
|
||||
|
||||
if (type != null) {
|
||||
SubmitPost.submitVideoPost(mExecutor, handler, newAuthenticatorOauthRetrofit, mUploadMediaRetrofit,
|
||||
mUploadVideoRetrofit, selectedAccount.getAccessToken(), subredditName, title, new File(cacheFilePath),
|
||||
type, resource, flair, isSpoiler, isNSFW, receivePostReplyNotifications,
|
||||
new SubmitPost.SubmitPostListener() {
|
||||
@Override
|
||||
public void submitSuccessful(Post post) {
|
||||
handler.post(() -> {
|
||||
EventBus.getDefault().post(new SubmitVideoOrGifPostEvent(true, false, null));
|
||||
if (type.contains("gif")) {
|
||||
Toast.makeText(SubmitPostService.this, R.string.gif_is_processing, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(SubmitPostService.this, R.string.video_is_processing, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
stopService();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void submitFailed(@Nullable String errorMessage) {
|
||||
handler.post(() -> EventBus.getDefault().post(new SubmitVideoOrGifPostEvent(false, false, errorMessage)));
|
||||
|
||||
stopService();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
handler.post(() -> EventBus.getDefault().post(new SubmitVideoOrGifPostEvent(false, true, null)));
|
||||
|
||||
stopService();
|
||||
}
|
||||
} catch (IOException | InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
handler.post(() -> EventBus.getDefault().post(new SubmitVideoOrGifPostEvent(false, true, null)));
|
||||
|
||||
stopService();
|
||||
}
|
||||
}
|
||||
|
||||
private void submitGalleryPost(Retrofit newAuthenticatorOauthRetrofit, Account selectedAccount, String payload) {
|
||||
try {
|
||||
|
||||
@@ -36,26 +36,12 @@ public class AboutPreferenceFragment extends CustomFontPreferenceFragmentCompat
|
||||
if (openSourcePreference != null) {
|
||||
openSourcePreference.setOnPreferenceClickListener(preference -> {
|
||||
Intent intent = new Intent(activity, LinkResolverActivity.class);
|
||||
intent.setData(Uri.parse("https://github.com/Docile-Alligator/Infinity-For-Reddit"));
|
||||
intent.setData(Uri.parse("https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy"));
|
||||
activity.startActivity(intent);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
if (ratePreference != null) {
|
||||
ratePreference.setOnPreferenceClickListener(preference -> {
|
||||
Intent playStoreIntent = new Intent(Intent.ACTION_VIEW);
|
||||
playStoreIntent.setData(Uri.parse("market://details?id=eu.toldi.infinityforlemmy"));
|
||||
if (playStoreIntent.resolveActivity(activity.getPackageManager()) != null) {
|
||||
activity.startActivity(playStoreIntent);
|
||||
} else {
|
||||
Intent intent = new Intent(activity, LinkResolverActivity.class);
|
||||
intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=eu.toldi.infinityforlemmy"));
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
if (emailPreference != null) {
|
||||
emailPreference.setOnPreferenceClickListener(preference -> {
|
||||
@@ -82,7 +68,7 @@ public class AboutPreferenceFragment extends CustomFontPreferenceFragmentCompat
|
||||
if (subredditPreference != null) {
|
||||
subredditPreference.setOnPreferenceClickListener(preference -> {
|
||||
Intent intent = new Intent(activity, LinkResolverActivity.class);
|
||||
intent.setData(Uri.parse("https://www.reddit.com/r/Infinity_For_Reddit"));
|
||||
intent.setData(Uri.parse("https://lemdro.id/c/infinityforlemmy"));
|
||||
activity.startActivity(intent);
|
||||
return true;
|
||||
});
|
||||
|
||||
@@ -35,6 +35,7 @@ import eu.toldi.infinityforlemmy.activities.SearchActivity;
|
||||
import eu.toldi.infinityforlemmy.activities.SettingsActivity;
|
||||
import eu.toldi.infinityforlemmy.activities.SubredditSelectionActivity;
|
||||
import eu.toldi.infinityforlemmy.multireddit.MultiReddit;
|
||||
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
|
||||
@@ -683,8 +684,8 @@ public class CustomizeMainPageTabsFragment extends Fragment {
|
||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||
switch (requestCode) {
|
||||
case 0:
|
||||
if (data.hasExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME)) {
|
||||
tab1CurrentName = data.getStringExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
if (data.hasExtra(SubredditSelectionActivity.EXTRA_RETURN_COMMUNITY_DATA)) {
|
||||
tab1CurrentName = ((SubscribedSubredditData) data.getParcelableExtra(SubredditSelectionActivity.EXTRA_RETURN_COMMUNITY_DATA)).getName();
|
||||
tab1NameSummaryTextView.setText(tab1CurrentName);
|
||||
mainActivityTabsSharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_1_NAME, tab1CurrentName).apply();
|
||||
} else if (data.hasExtra(MultiredditSelectionActivity.EXTRA_RETURN_MULTIREDDIT)) {
|
||||
@@ -701,8 +702,8 @@ public class CustomizeMainPageTabsFragment extends Fragment {
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (data.hasExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME)) {
|
||||
tab2CurrentName = data.getStringExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
if (data.hasExtra(SubredditSelectionActivity.EXTRA_RETURN_COMMUNITY_DATA)) {
|
||||
tab2CurrentName = ((SubscribedSubredditData) data.getParcelableExtra(SubredditSelectionActivity.EXTRA_RETURN_COMMUNITY_DATA)).getName();
|
||||
tab2NameSummaryTextView.setText(tab2CurrentName);
|
||||
mainActivityTabsSharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_2_NAME, tab2CurrentName).apply();
|
||||
} else if (data.hasExtra(MultiredditSelectionActivity.EXTRA_RETURN_MULTIREDDIT)) {
|
||||
@@ -719,8 +720,8 @@ public class CustomizeMainPageTabsFragment extends Fragment {
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (data.hasExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME)) {
|
||||
tab3CurrentName = data.getStringExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
|
||||
if (data.hasExtra(SubredditSelectionActivity.EXTRA_RETURN_COMMUNITY_DATA)) {
|
||||
tab3CurrentName = ((SubscribedSubredditData) data.getParcelableExtra(SubredditSelectionActivity.EXTRA_RETURN_COMMUNITY_DATA)).getName();
|
||||
tab3NameSummaryTextView.setText(tab3CurrentName);
|
||||
mainActivityTabsSharedPreferences.edit().putString((accountName == null ? "" : accountName) + SharedPreferencesUtils.MAIN_PAGE_TAB_3_NAME, tab3CurrentName).apply();
|
||||
} else if (data.hasExtra(MultiredditSelectionActivity.EXTRA_RETURN_MULTIREDDIT)) {
|
||||
|
||||
@@ -6,7 +6,6 @@ import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTI
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.biometric.BiometricManager;
|
||||
@@ -17,7 +16,6 @@ import javax.inject.Named;
|
||||
|
||||
import eu.toldi.infinityforlemmy.Infinity;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.activities.LinkResolverActivity;
|
||||
import eu.toldi.infinityforlemmy.activities.PostFilterPreferenceActivity;
|
||||
import eu.toldi.infinityforlemmy.customviews.CustomFontPreferenceFragmentCompat;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
@@ -52,26 +50,5 @@ public class MainPreferenceFragment extends CustomFontPreferenceFragmentCompat {
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
if (privacyPolicyPreference != null) {
|
||||
privacyPolicyPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
Intent intent = new Intent(activity, LinkResolverActivity.class);
|
||||
intent.setData(Uri.parse("https://docile-alligator.github.io/"));
|
||||
activity.startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (redditUserAgreementPreference != null) {
|
||||
redditUserAgreementPreference.setOnPreferenceClickListener(preference -> {
|
||||
Intent intent = new Intent(activity, LinkResolverActivity.class);
|
||||
intent.setData(Uri.parse("https://www.redditinc.com/policies/user-agreement-september-12-2021"));
|
||||
activity.startActivity(intent);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ public class MiscellaneousPreferenceFragment extends CustomFontPreferenceFragmen
|
||||
ListPreference mainPageBackButtonActionListPreference = findPreference(SharedPreferencesUtils.MAIN_PAGE_BACK_BUTTON_ACTION);
|
||||
SwitchPreference savePostFeedScrolledPositionSwitch = findPreference(SharedPreferencesUtils.SAVE_FRONT_PAGE_SCROLLED_POSITION);
|
||||
ListPreference languageListPreference = findPreference(SharedPreferencesUtils.LANGUAGE);
|
||||
EditTextPreference anonymousAccountInstance = findPreference(SharedPreferencesUtils.ANONYMOUS_ACCOUNT_INSTANCE);
|
||||
EditTextPreference postFeedMaxResolution = findPreference(SharedPreferencesUtils.POST_FEED_MAX_RESOLUTION);
|
||||
|
||||
if (mainPageBackButtonActionListPreference != null) {
|
||||
@@ -66,6 +67,25 @@ public class MiscellaneousPreferenceFragment extends CustomFontPreferenceFragmen
|
||||
});
|
||||
}
|
||||
|
||||
if (anonymousAccountInstance != null) {
|
||||
anonymousAccountInstance.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
String url = (String) newValue;
|
||||
if (url == null || url.equals("")) {
|
||||
Toast.makeText(activity, R.string.url_cannot_be_null_or_empty, Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
if (!url.startsWith("http://") && !url.startsWith("https://")) {
|
||||
Toast.makeText(activity, "The url has to start with https:// or http://", Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
EventBus.getDefault().post(new RecreateActivityEvent());
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
if (postFeedMaxResolution != null) {
|
||||
postFeedMaxResolution.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
try {
|
||||
|
||||
@@ -4,26 +4,24 @@ import android.os.Handler;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
|
||||
import eu.toldi.infinityforlemmy.account.Account;
|
||||
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||
import eu.toldi.infinityforlemmy.dto.FollowCommunityDTO;
|
||||
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class SubredditSubscription {
|
||||
public static void subscribeToSubreddit(Executor executor, Handler handler, Retrofit oauthRetrofit,
|
||||
Retrofit retrofit, String accessToken, String subredditName,
|
||||
public class CommunitySubscription {
|
||||
public static void subscribeToCommunity(Executor executor, Handler handler,
|
||||
Retrofit retrofit, String accessToken, int communityId, String communityQualifiedName,
|
||||
String accountName, RedditDataRoomDatabase redditDataRoomDatabase,
|
||||
SubredditSubscriptionListener subredditSubscriptionListener) {
|
||||
subredditSubscription(executor, handler, oauthRetrofit, retrofit, accessToken, subredditName,
|
||||
communitySubscription(executor, handler, retrofit, accessToken, communityId, communityQualifiedName,
|
||||
accountName, "sub", redditDataRoomDatabase, subredditSubscriptionListener);
|
||||
}
|
||||
|
||||
@@ -31,7 +29,7 @@ public class SubredditSubscription {
|
||||
RedditDataRoomDatabase redditDataRoomDatabase,
|
||||
String subredditName,
|
||||
SubredditSubscriptionListener subredditSubscriptionListener) {
|
||||
FetchSubredditData.fetchSubredditData(null, retrofit, subredditName, "", new FetchSubredditData.FetchSubredditDataListener() {
|
||||
FetchSubredditData.fetchSubredditData(retrofit, subredditName, null, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
insertSubscription(executor, handler, redditDataRoomDatabase,
|
||||
@@ -45,11 +43,11 @@ public class SubredditSubscription {
|
||||
});
|
||||
}
|
||||
|
||||
public static void unsubscribeToSubreddit(Executor executor, Handler handler, Retrofit oauthRetrofit,
|
||||
String accessToken, String subredditName, String accountName,
|
||||
public static void unsubscribeToCommunity(Executor executor, Handler handler,
|
||||
Retrofit retrofit, String accessToken, int communityId, String communityQualifiedName, String accountName,
|
||||
RedditDataRoomDatabase redditDataRoomDatabase,
|
||||
SubredditSubscriptionListener subredditSubscriptionListener) {
|
||||
subredditSubscription(executor, handler, oauthRetrofit, null, accessToken, subredditName,
|
||||
communitySubscription(executor, handler, retrofit, accessToken, communityId, communityQualifiedName,
|
||||
accountName, "unsub", redditDataRoomDatabase, subredditSubscriptionListener);
|
||||
}
|
||||
|
||||
@@ -60,24 +58,21 @@ public class SubredditSubscription {
|
||||
removeSubscription(executor, handler, redditDataRoomDatabase, subredditName, "-", subredditSubscriptionListener);
|
||||
}
|
||||
|
||||
private static void subredditSubscription(Executor executor, Handler handler, Retrofit oauthRetrofit,
|
||||
Retrofit retrofit, String accessToken, String subredditName,
|
||||
private static void communitySubscription(Executor executor, Handler handler,
|
||||
Retrofit retrofit, String accessToken, int communityId, String communityQualifiedName,
|
||||
String accountName, String action,
|
||||
RedditDataRoomDatabase redditDataRoomDatabase,
|
||||
SubredditSubscriptionListener subredditSubscriptionListener) {
|
||||
RedditAPI api = oauthRetrofit.create(RedditAPI.class);
|
||||
LemmyAPI api = retrofit.create(LemmyAPI.class);
|
||||
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put(APIUtils.ACTION_KEY, action);
|
||||
params.put(APIUtils.SR_NAME_KEY, subredditName);
|
||||
|
||||
Call<String> subredditSubscriptionCall = api.subredditSubscription(APIUtils.getOAuthHeader(accessToken), params);
|
||||
Call<String> subredditSubscriptionCall = api.communityFollow(new FollowCommunityDTO(communityId, action.equals("sub"), accessToken));
|
||||
subredditSubscriptionCall.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
if (action.equals("sub")) {
|
||||
FetchSubredditData.fetchSubredditData(oauthRetrofit, retrofit, subredditName, accessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
FetchSubredditData.fetchSubredditData(retrofit, communityQualifiedName, accessToken, new FetchSubredditData.FetchSubredditDataListener() {
|
||||
@Override
|
||||
public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
|
||||
insertSubscription(executor, handler, redditDataRoomDatabase,
|
||||
@@ -90,7 +85,7 @@ public class SubredditSubscription {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
removeSubscription(executor, handler, redditDataRoomDatabase, subredditName,
|
||||
removeSubscription(executor, handler, redditDataRoomDatabase, communityQualifiedName,
|
||||
accountName, subredditSubscriptionListener);
|
||||
}
|
||||
} else {
|
||||
@@ -116,7 +111,7 @@ public class SubredditSubscription {
|
||||
SubredditData subredditData, String accountName,
|
||||
SubredditSubscriptionListener subredditSubscriptionListener) {
|
||||
executor.execute(() -> {
|
||||
SubscribedSubredditData subscribedSubredditData = new SubscribedSubredditData(subredditData.getId(), LemmyUtils.actorID2FullName(subredditData.getActorId()), subredditData.getName(),
|
||||
SubscribedSubredditData subscribedSubredditData = new SubscribedSubredditData(subredditData.getId(), subredditData.getName(), LemmyUtils.actorID2FullName(subredditData.getActorId()),
|
||||
subredditData.getIconUrl(), accountName);
|
||||
if (accountName.equals("-")) {
|
||||
if (!redditDataRoomDatabase.accountDao().isAnonymousAccountInserted()) {
|
||||
@@ -12,11 +12,11 @@ import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class FetchSubredditData {
|
||||
public static void fetchSubredditData(Retrofit oauthRetrofit, Retrofit retrofit, String subredditName, String accessToken, final FetchSubredditDataListener fetchSubredditDataListener) {
|
||||
public static void fetchSubredditData(Retrofit retrofit, String subredditName, String accessToken, final FetchSubredditDataListener fetchSubredditDataListener) {
|
||||
LemmyAPI api = retrofit.create(LemmyAPI.class);
|
||||
|
||||
Call<String> subredditData;
|
||||
subredditData = api.communityInfo(subredditName,accessToken);
|
||||
subredditData = api.communityInfo(subredditName, accessToken);
|
||||
|
||||
subredditData.enqueue(new Callback<>() {
|
||||
@Override
|
||||
|
||||
@@ -41,10 +41,18 @@ public class ParseSubredditData {
|
||||
}
|
||||
int id = community.getInt("id");
|
||||
String name = community.getString("name");
|
||||
String description = community.getString("description");
|
||||
String description = "";
|
||||
if (!community.isNull("description")) {
|
||||
description = community.getString("description");
|
||||
}
|
||||
|
||||
boolean removed = community.getBoolean("removed");
|
||||
String published = community.getString("published");
|
||||
String updated = community.getString("updated");
|
||||
String updated = "";
|
||||
if (!community.isNull("updated")) {
|
||||
updated = community.getString("updated");
|
||||
}
|
||||
|
||||
boolean deleted = community.getBoolean("deleted");
|
||||
|
||||
String actorId = community.getString("actor_id");
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
package eu.toldi.infinityforlemmy.subscribedsubreddit;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.ColumnInfo;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.ForeignKey;
|
||||
|
||||
import eu.toldi.infinityforlemmy.account.Account;
|
||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
|
||||
|
||||
@Entity(tableName = "subscribed_subreddits", primaryKeys = {"id", "username"},
|
||||
foreignKeys = @ForeignKey(entity = Account.class, parentColumns = "username",
|
||||
childColumns = "username", onDelete = ForeignKey.CASCADE))
|
||||
public class SubscribedSubredditData {
|
||||
childColumns = "username", onDelete = ForeignKey.CASCADE))
|
||||
public class SubscribedSubredditData implements Parcelable {
|
||||
@NonNull
|
||||
@ColumnInfo(name = "id")
|
||||
private int id;
|
||||
@@ -25,12 +30,20 @@ public class SubscribedSubredditData {
|
||||
@ColumnInfo(name = "username")
|
||||
private String username;
|
||||
|
||||
public SubscribedSubredditData(@NonNull int id, String name,@NonNull String qualified_name, String iconUrl, @NonNull String username) {
|
||||
public SubscribedSubredditData(@NonNull int id, String name, @NonNull String qualified_name, String iconUrl, @NonNull String username) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.iconUrl = iconUrl;
|
||||
this.username = username;
|
||||
this.qualified_name =qualified_name;
|
||||
this.qualified_name = qualified_name;
|
||||
}
|
||||
|
||||
public SubscribedSubredditData(@NonNull SubredditData communityData) {
|
||||
this.id = communityData.getId();
|
||||
this.name = communityData.getName();
|
||||
this.iconUrl = communityData.getIconUrl();
|
||||
this.username = "-";
|
||||
this.qualified_name = LemmyUtils.actorID2FullName(communityData.getActorId());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -63,4 +76,38 @@ public class SubscribedSubredditData {
|
||||
public void setUsername(@NonNull String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(@NonNull Parcel parcel, int i) {
|
||||
parcel.writeInt(id);
|
||||
parcel.writeString(name);
|
||||
parcel.writeString(iconUrl);
|
||||
parcel.writeString(username);
|
||||
parcel.writeString(qualified_name);
|
||||
}
|
||||
|
||||
public SubscribedSubredditData(Parcel in) {
|
||||
id = in.readInt();
|
||||
name = in.readString();
|
||||
iconUrl = in.readString();
|
||||
username = in.readString();
|
||||
qualified_name = in.readString();
|
||||
}
|
||||
|
||||
public static final Creator<SubscribedSubredditData> CREATOR = new Creator<>() {
|
||||
@Override
|
||||
public SubscribedSubredditData createFromParcel(Parcel in) {
|
||||
return new SubscribedSubredditData(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubscribedSubredditData[] newArray(int size) {
|
||||
return new SubscribedSubredditData[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public interface UserDao {
|
||||
LiveData<UserData> getUserLiveData(String userName);
|
||||
|
||||
@Query("SELECT * FROM users WHERE actor_id = :actor_id COLLATE NOCASE LIMIT 1")
|
||||
LiveData<UserData> getUserLiveDataByQualifiedName(String actor_id);
|
||||
LiveData<UserData> getUserLiveDataByActorId(String actor_id);
|
||||
|
||||
@Query("SELECT * FROM users WHERE name = :userName COLLATE NOCASE LIMIT 1")
|
||||
UserData getUserData(String userName);
|
||||
|
||||
@@ -12,7 +12,7 @@ public class UserRepository {
|
||||
|
||||
UserRepository(RedditDataRoomDatabase redditDataRoomDatabase, String actor_id) {
|
||||
mUserDao = redditDataRoomDatabase.userDao();
|
||||
mUserLiveData = mUserDao.getUserLiveData(actor_id);
|
||||
mUserLiveData = mUserDao.getUserLiveDataByActorId(actor_id);
|
||||
}
|
||||
|
||||
LiveData<UserData> getUserLiveData() {
|
||||
|
||||
@@ -15,7 +15,7 @@ import okhttp3.RequestBody;
|
||||
public class APIUtils {
|
||||
public static final String OAUTH_URL = "https://www.reddit.com/api/v1/authorize.compact";
|
||||
public static final String OAUTH_API_BASE_URI = "https://oauth.reddit.com";
|
||||
public static final String API_BASE_URI = "https://lemmy.toldi.eu";
|
||||
public static final String API_BASE_URI = "https://lemmy.world";
|
||||
public static final String API_UPLOAD_MEDIA_URI = "https://reddit-uploaded-media.s3-accelerate.amazonaws.com";
|
||||
public static final String API_UPLOAD_VIDEO_URI = "https://reddit-uploaded-video.s3-accelerate.amazonaws.com";
|
||||
public static final String GFYCAT_API_BASE_URI = "https://api.gfycat.com/v1/gfycats/";
|
||||
|
||||
@@ -167,6 +167,8 @@ public class SharedPreferencesUtils {
|
||||
public static final int SWIPE_ACITON_DOWNVOTE = 1;
|
||||
public static final String LANGUAGE = "language";
|
||||
public static final String LANGUAGE_DEFAULT_VALUE = "auto";
|
||||
|
||||
public static final String ANONYMOUS_ACCOUNT_INSTANCE = "anonymous_account_instance";
|
||||
public static final String ENABLE_SEARCH_HISTORY = "enable_search_history";
|
||||
public static final String POST_FILTER = "post_filter";
|
||||
public static final String ONLY_DISABLE_PREVIEW_IN_VIDEO_AND_GIF_POSTS = "only_disable_preview_in_video_and_gif_posts";
|
||||
|
||||
@@ -17,55 +17,41 @@ import java.io.StringReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.MultipartBody;
|
||||
import okhttp3.RequestBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
public class UploadImageUtils {
|
||||
@Nullable
|
||||
public static String uploadImage(Retrofit oauthRetrofit, Retrofit uploadMediaRetrofit,
|
||||
public static String uploadImage(RetrofitHolder mRetrofit,
|
||||
String accessToken, Bitmap image) throws IOException, JSONException, XmlPullParserException {
|
||||
return uploadImage(oauthRetrofit, uploadMediaRetrofit, accessToken, image, false);
|
||||
return uploadImage(mRetrofit, accessToken, image, false);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String uploadImage(Retrofit oauthRetrofit, Retrofit uploadMediaRetrofit,
|
||||
String accessToken, Bitmap image, boolean returnResponseForGallerySubmission) throws IOException, JSONException, XmlPullParserException {
|
||||
RedditAPI api = oauthRetrofit.create(RedditAPI.class);
|
||||
public static String uploadImage(RetrofitHolder mRetrofit,
|
||||
String accessToken, Bitmap image, boolean returnResponseForGallerySubmission) throws IOException, JSONException, XmlPullParserException {
|
||||
|
||||
Map<String, String> uploadImageParams = new HashMap<>();
|
||||
uploadImageParams.put(APIUtils.FILEPATH_KEY, "post_image.jpg");
|
||||
uploadImageParams.put(APIUtils.MIMETYPE_KEY, "image/jpeg");
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
image.compress(Bitmap.CompressFormat.JPEG, 100, stream);
|
||||
byte[] byteArray = stream.toByteArray();
|
||||
|
||||
Call<String> uploadImageCall = api.uploadImage(APIUtils.getOAuthHeader(accessToken), uploadImageParams);
|
||||
Response<String> uploadImageResponse = uploadImageCall.execute();
|
||||
if (uploadImageResponse.isSuccessful()) {
|
||||
Map<String, RequestBody> nameValuePairsMap = parseJSONResponseFromAWS(uploadImageResponse.body());
|
||||
RequestBody fileBody = RequestBody.create(byteArray, MediaType.parse("application/octet-stream"));
|
||||
MultipartBody.Part fileToUpload = MultipartBody.Part.createFormData("images[]", "post_image.jpg", fileBody);
|
||||
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
image.compress(Bitmap.CompressFormat.JPEG, 100, stream);
|
||||
byte[] byteArray = stream.toByteArray();
|
||||
|
||||
RequestBody fileBody = RequestBody.create(byteArray, MediaType.parse("application/octet-stream"));
|
||||
MultipartBody.Part fileToUpload = MultipartBody.Part.createFormData("file", "post_image.jpg", fileBody);
|
||||
|
||||
RedditAPI uploadMediaToAWSApi = uploadMediaRetrofit.create(RedditAPI.class);
|
||||
Call<String> uploadMediaToAWS = uploadMediaToAWSApi.uploadMediaToAWS(nameValuePairsMap, fileToUpload);
|
||||
Response<String> uploadMediaToAWSResponse = uploadMediaToAWS.execute();
|
||||
if (uploadMediaToAWSResponse.isSuccessful()) {
|
||||
if (returnResponseForGallerySubmission) {
|
||||
return uploadImageResponse.body();
|
||||
}
|
||||
return parseXMLResponseFromAWS(uploadMediaToAWSResponse.body());
|
||||
} else {
|
||||
return "Error: " + uploadMediaToAWSResponse.code();
|
||||
}
|
||||
LemmyAPI api = mRetrofit.getRetrofit().create(LemmyAPI.class);
|
||||
Call<String> uploadMedia = api.uploadImage("jwt=" + accessToken, fileToUpload);
|
||||
Response<String> uploadMediaResponse = uploadMedia.execute();
|
||||
if (uploadMediaResponse.isSuccessful()) {
|
||||
JSONObject responseObject = new JSONObject(uploadMediaResponse.body());
|
||||
String fileName = responseObject.getJSONArray("files").getJSONObject(0).getString("file");
|
||||
return mRetrofit.getBaseURL() + "/pictrs/image/" + fileName;
|
||||
} else {
|
||||
return "Error: " + uploadImageResponse.message();
|
||||
return "Error: " + uploadMediaResponse.code();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,11 +53,11 @@ import java.util.concurrent.Executor;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import io.noties.markwon.core.spans.CustomTypefaceSpan;
|
||||
import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import eu.toldi.infinityforlemmy.SortType;
|
||||
import eu.toldi.infinityforlemmy.UploadedImage;
|
||||
import retrofit2.Retrofit;
|
||||
import io.noties.markwon.core.spans.CustomTypefaceSpan;
|
||||
|
||||
public final class Utils {
|
||||
public static final int NETWORK_TYPE_OTHER = -1;
|
||||
@@ -361,8 +361,8 @@ public final class Utils {
|
||||
return drawable;
|
||||
}
|
||||
|
||||
public static void uploadImageToReddit(Context context, Executor executor, Retrofit oauthRetrofit,
|
||||
Retrofit uploadMediaRetrofit, String accessToken, EditText editText,
|
||||
public static void uploadImageToReddit(Context context, Executor executor, RetrofitHolder retrofit,
|
||||
String accessToken, EditText editText,
|
||||
CoordinatorLayout coordinatorLayout, Uri imageUri,
|
||||
ArrayList<UploadedImage> uploadedImages) {
|
||||
Toast.makeText(context, R.string.uploading_image, Toast.LENGTH_SHORT).show();
|
||||
@@ -370,7 +370,7 @@ public final class Utils {
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
Bitmap bitmap = Glide.with(context).asBitmap().load(imageUri).submit().get();
|
||||
String imageUrlOrError = UploadImageUtils.uploadImage(oauthRetrofit, uploadMediaRetrofit, accessToken, bitmap);
|
||||
String imageUrlOrError = UploadImageUtils.uploadImage(retrofit, accessToken, bitmap);
|
||||
handler.post(() -> {
|
||||
if (imageUrlOrError != null && !imageUrlOrError.startsWith("Error: ")) {
|
||||
String fileName = Utils.getFileName(context, imageUri);
|
||||
|
||||
@@ -1,54 +1,160 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="169.4dp"
|
||||
android:height="141.4dp"
|
||||
android:viewportWidth="169.4"
|
||||
android:viewportHeight="141.4">
|
||||
<path
|
||||
android:pathData="M38.199,118.602L38.138,119.349C37.838,123.044 34.951,135.916 34.951,135.916L38.507,137.579C38.507,137.579 40.936,134.715 48.987,122.37L50.023,121.586L38.199,118.602Z"
|
||||
android:fillColor="#009559"/>
|
||||
android:pathData="M38.2,118.6L38.14,119.35C37.84,123.04 34.95,135.92 34.95,135.92L38.51,137.58C38.51,137.58 40.94,134.71 48.99,122.37L50.02,121.59L38.2,118.6Z"
|
||||
android:fillColor="#dbd548" />
|
||||
<path
|
||||
android:pathData="M75.846,122.66L77.807,141.366L82.5,141.313L84.925,122.66L75.846,122.66Z"
|
||||
android:fillColor="#009559"/>
|
||||
android:pathData="M75.85,122.66L77.81,141.37L82.5,141.31L84.93,122.66L75.85,122.66Z"
|
||||
android:fillColor="#dbd548" />
|
||||
<path
|
||||
android:pathData="M126.591,118.196L117.925,122.267L130.964,135.15L134.409,132.275L126.591,118.196Z"
|
||||
android:fillColor="#009559"/>
|
||||
android:pathData="M126.59,118.2L117.93,122.27L130.96,135.15L134.41,132.27L126.59,118.2Z"
|
||||
android:fillColor="#dbd548" />
|
||||
<path
|
||||
android:pathData="M169.36,89.86C169.36,110.142 131.447,126.584 84.68,126.584C37.913,126.584 0,110.142 0,89.86C0,69.578 37.913,53.137 84.68,53.137C131.447,53.137 169.36,69.578 169.36,89.86Z"
|
||||
android:fillColor="#00B57C"/>
|
||||
android:pathData="M169.36,89.86C169.36,110.14 131.45,126.58 84.68,126.58C37.91,126.58 0,110.14 0,89.86C0,69.58 37.91,53.14 84.68,53.14C131.45,53.14 169.36,69.58 169.36,89.86Z"
|
||||
android:fillColor="#f1ea4f" />
|
||||
<path
|
||||
android:pathData="M90.422,111.47C90.328,113.622 87.585,115.251 84.296,115.107C81.007,114.964 78.417,113.102 78.511,110.949C78.605,108.796 81.348,107.167 84.637,107.311C87.926,107.455 90.516,109.317 90.422,111.47Z"
|
||||
android:fillColor="#645EB2"/>
|
||||
android:pathData="M90.42,111.47C90.33,113.62 87.58,115.25 84.3,115.11C81.01,114.96 78.42,113.1 78.51,110.95C78.61,108.8 81.35,107.17 84.64,107.31C87.93,107.46 90.52,109.32 90.42,111.47Z"
|
||||
android:fillColor="#04b5b3" />
|
||||
<path
|
||||
android:pathData="M128.993,107.476C128.912,109.33 126.083,110.712 122.675,110.563C119.265,110.414 116.568,108.79 116.649,106.936C116.73,105.082 119.559,103.7 122.968,103.85C126.377,103.998 129.074,105.622 128.993,107.476Z"
|
||||
android:fillColor="#645EB2"/>
|
||||
android:pathData="M128.99,107.48C128.91,109.33 126.08,110.71 122.68,110.56C119.26,110.41 116.57,108.79 116.65,106.94C116.73,105.08 119.56,103.7 122.97,103.85C126.38,104 129.07,105.62 128.99,107.48Z"
|
||||
android:fillColor="#04b5b3" />
|
||||
<path
|
||||
android:pathData="M154.836,93.616C154.75,95.59 151.819,97.064 148.291,96.91C144.763,96.756 141.973,95.031 142.059,93.057C142.145,91.084 145.075,89.609 148.604,89.763C152.132,89.918 154.922,91.642 154.836,93.616Z"
|
||||
android:fillColor="#645EB2"/>
|
||||
android:pathData="M154.84,93.62C154.75,95.59 151.82,97.06 148.29,96.91C144.76,96.76 141.97,95.03 142.06,93.06C142.15,91.08 145.07,89.61 148.6,89.76C152.13,89.92 154.92,91.64 154.84,93.62Z"
|
||||
android:fillColor="#04b5b3" />
|
||||
<path
|
||||
android:pathData="M43.44,105.996C43.526,104.022 46.456,102.548 49.984,102.702C53.513,102.856 56.303,104.581 56.217,106.555C56.13,108.528 53.2,110.003 49.672,109.849C46.144,109.694 43.354,107.97 43.44,105.996Z"
|
||||
android:fillColor="#645EB2"/>
|
||||
android:pathData="M43.44,106C43.53,104.02 46.46,102.55 49.98,102.7C53.51,102.86 56.3,104.58 56.22,106.56C56.13,108.53 53.2,110 49.67,109.85C46.14,109.69 43.35,107.97 43.44,106Z"
|
||||
android:fillColor="#04b5b3" />
|
||||
<path
|
||||
android:pathData="M14.525,93.977C14.608,92.063 17.682,90.644 21.39,90.806C25.098,90.968 28.035,92.65 27.952,94.564C27.868,96.477 24.795,97.897 21.087,97.735C17.379,97.573 14.442,95.891 14.525,93.977Z"
|
||||
android:fillColor="#645EB2"/>
|
||||
android:pathData="M14.52,93.98C14.61,92.06 17.68,90.64 21.39,90.81C25.1,90.97 28.03,92.65 27.95,94.56C27.87,96.48 24.8,97.9 21.09,97.74C17.38,97.57 14.44,95.89 14.52,93.98Z"
|
||||
android:fillColor="#04b5b3" />
|
||||
<path
|
||||
android:pathData="M84.062,97.111C66.262,97.111 45.617,93.636 23.471,83.362L23.138,83.208L23.108,82.844C23.094,82.672 21.762,65.428 28.579,46.557C33.593,32.679 43.946,15.63 65.301,5.251C82.613,-3.164 103.387,-1.522 118.349,10.589C118.876,11.016 119.403,11.458 119.927,11.916C135.893,25.86 144.782,49.219 146.349,81.347L146.367,81.715L146.054,81.911C145.69,82.137 121.009,97.111 84.062,97.111Z"
|
||||
android:fillColor="#98F4ED"/>
|
||||
android:pathData="M84.06,97.11C66.26,97.11 45.62,93.64 23.47,83.36L23.14,83.21L23.11,82.84C23.09,82.67 21.76,65.43 28.58,46.56C33.59,32.68 43.95,15.63 65.3,5.25C82.61,-3.16 103.39,-1.52 118.35,10.59C118.88,11.02 119.4,11.46 119.93,11.92C135.89,25.86 144.78,49.22 146.35,81.35L146.37,81.71L146.05,81.91C145.69,82.14 121.01,97.11 84.06,97.11Z"
|
||||
android:fillColor="#000f44" />
|
||||
<path
|
||||
android:pathData="M128.431,64.821C124.241,54.604 116.516,40.949 102.949,34.717C104.034,31.924 106.031,27.559 107.143,25.166C107.239,25.177 107.334,25.191 107.433,25.189C108.544,25.169 109.428,24.251 109.407,23.14C109.386,22.029 108.469,21.146 107.358,21.166C106.247,21.187 105.363,22.105 105.384,23.216C105.394,23.774 105.632,24.274 106.006,24.632C104.895,27.017 102.916,31.342 101.8,34.206C96.796,32.114 91.026,31.027 84.38,31.449L83.964,17.33C84.737,17.049 85.292,16.315 85.292,15.445C85.292,14.334 84.391,13.433 83.281,13.433C82.169,13.433 81.268,14.334 81.268,15.445C81.268,16.356 81.878,17.117 82.709,17.364L83.127,31.558C82.643,31.602 82.165,31.636 81.673,31.696C75.498,32.445 70.169,33.859 65.526,35.742C64.048,31.651 61.872,27.584 60.631,25.398C60.948,25.035 61.141,24.562 61.131,24.043C61.11,22.932 60.193,22.048 59.082,22.069C57.971,22.09 57.087,23.007 57.108,24.118C57.129,25.229 58.046,26.113 59.157,26.092C59.292,26.09 59.423,26.072 59.549,26.045C60.775,28.212 62.924,32.241 64.359,36.217C36.951,48.109 35.332,77.364 35.765,88.447C53.262,94.817 69.601,97.111 84.062,97.111C106.644,97.111 124.631,91.519 135.297,87.117C134.255,82.183 132.172,73.941 128.431,64.821Z"
|
||||
android:fillColor="#FFF0BB"/>
|
||||
android:pathData="M51.69,70.02a32.61,28.34 0,1 0,65.21 0a32.61,28.34 0,1 0,-65.21 0z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="1.29152"
|
||||
android:strokeColor="#00000000">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:startX="51.69"
|
||||
android:startY="70.02"
|
||||
android:endX="116.9"
|
||||
android:endY="70.02"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:offset="0"
|
||||
android:color="#FF496A6A" />
|
||||
<item
|
||||
android:offset="1"
|
||||
android:color="#FF395A63" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:pathData="M77.172,61.355C78.097,62.842 79.504,64.214 81.139,64.875C84.381,66.185 87.04,63.967 88.914,61.501C89.624,60.566 88.041,59.656 87.339,60.58C85.689,62.751 83.405,64.419 80.849,62.651C80.025,62.081 79.279,61.288 78.748,60.434C78.128,59.439 76.549,60.354 77.172,61.355Z"
|
||||
android:fillColor="#032560"/>
|
||||
android:pathData="M99.66,46.48a16.46,16.23 0,1 0,32.92 0a16.46,16.23 0,1 0,-32.92 0z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="0.873869"
|
||||
android:strokeColor="#00000000">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:startX="99.66"
|
||||
android:startY="46.48"
|
||||
android:endX="132.59"
|
||||
android:endY="46.48"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:offset="0"
|
||||
android:color="#FF496A6A" />
|
||||
<item
|
||||
android:offset="1"
|
||||
android:color="#FF395A63" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:pathData="M71.48,50.672C71.48,51.821 70.548,52.753 69.399,52.753C68.251,52.753 67.319,51.821 67.319,50.672C67.319,49.523 68.251,48.591 69.399,48.591C70.548,48.591 71.48,49.523 71.48,50.672Z"
|
||||
android:fillColor="#032560"/>
|
||||
android:pathData="M106.91,54.08a10.73,11.44 106.75,1 0,18.52 -11.92a10.73,11.44 106.75,1 0,-18.52 11.92z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="1.0805"
|
||||
android:strokeColor="#00000000">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:startX="106.52"
|
||||
android:startY="54.33"
|
||||
android:endX="125.81"
|
||||
android:endY="41.9"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:offset="0.06"
|
||||
android:color="#FFFF8684" />
|
||||
<item
|
||||
android:offset="0.9"
|
||||
android:color="#FFFFC9C1" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:pathData="M98.167,50.672C98.167,51.821 97.235,52.753 96.086,52.753C94.937,52.753 94.006,51.821 94.006,50.672C94.006,49.523 94.937,48.591 96.086,48.591C97.235,48.591 98.167,49.523 98.167,50.672Z"
|
||||
android:fillColor="#032560"/>
|
||||
android:pathData="M36.81,46.66a16.46,16.23 0,1 0,32.92 0a16.46,16.23 0,1 0,-32.92 0z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="0.873869"
|
||||
android:strokeColor="#00000000">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:startX="36.81"
|
||||
android:startY="46.66"
|
||||
android:endX="69.74"
|
||||
android:endY="46.66"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:offset="0"
|
||||
android:color="#FF395A63" />
|
||||
<item
|
||||
android:offset="1"
|
||||
android:color="#FF496A6A" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:pathData="M70.092,59.487C70.092,61.525 68.216,63.177 65.902,63.177C63.588,63.177 61.712,61.525 61.712,59.487C61.712,57.449 63.588,55.798 65.902,55.798C68.216,55.798 70.092,57.449 70.092,59.487Z"
|
||||
android:fillColor="#FFAB3D"/>
|
||||
android:pathData="M53.45,37.54a10.57,11.61 90.26,1 0,-0.1 21.14a10.57,11.61 90.26,1 0,0.1 -21.14z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="1.07946"
|
||||
android:strokeColor="#00000000">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:startX="53.45"
|
||||
android:startY="37.1"
|
||||
android:endX="53.35"
|
||||
android:endY="59.13"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:offset="0.1"
|
||||
android:color="#FFFFC9C1" />
|
||||
<item
|
||||
android:offset="0.94"
|
||||
android:color="#FFFF8684" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:pathData="M102.81,59.487C102.81,61.525 100.934,63.177 98.62,63.177C96.306,63.177 94.43,61.525 94.43,59.487C94.43,57.449 96.306,55.798 98.62,55.798C100.934,55.798 102.81,57.449 102.81,59.487Z"
|
||||
android:fillColor="#FFAB3D"/>
|
||||
android:pathData="M82.15,75.67a2.45,3.99 0,1 0,4.9 0a2.45,3.99 0,1 0,-4.9 0z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="0.778139"
|
||||
android:fillColor="#000000"
|
||||
android:strokeColor="#00000000" />
|
||||
<path
|
||||
android:pathData="M65.4,70.69a3.54,4.31 0,1 0,7.07 0a3.54,4.31 0,1 0,-7.07 0z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="0.778139"
|
||||
android:fillColor="#000000"
|
||||
android:strokeColor="#00000000" />
|
||||
<path
|
||||
android:pathData="M96.31,70.56a3.54,4.31 0,1 0,7.07 0a3.54,4.31 0,1 0,-7.07 0z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="0.778139"
|
||||
android:fillColor="#000000"
|
||||
android:strokeColor="#00000000" />
|
||||
</vector>
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:hint="@string/instance_url"
|
||||
android:inputType="textUri"
|
||||
android:maxLines="1" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
@@ -90,6 +91,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/user_password"
|
||||
android:maxLength="60"
|
||||
android:maxLines="1"
|
||||
android:password="true" />
|
||||
|
||||
|
||||
@@ -109,35 +109,6 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.libRG.CustomTextView
|
||||
android:id="@+id/flair_custom_text_view_post_gallery_activity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:padding="4dp"
|
||||
android:text="@string/flair"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="?attr/font_default"
|
||||
android:fontFamily="?attr/font_family"
|
||||
android:visibility="gone"
|
||||
app:lib_setRadius="6dp"
|
||||
app:lib_setRoundedView="true"
|
||||
app:lib_setShape="rectangle" />
|
||||
|
||||
<com.libRG.CustomTextView
|
||||
android:id="@+id/spoiler_custom_text_view_post_gallery_activity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:padding="4dp"
|
||||
android:text="@string/spoiler"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="?attr/font_default"
|
||||
android:fontFamily="?attr/font_family"
|
||||
app:lib_setRadius="6dp"
|
||||
app:lib_setRoundedView="true"
|
||||
app:lib_setShape="rectangle" />
|
||||
|
||||
<com.libRG.CustomTextView
|
||||
android:id="@+id/nsfw_custom_text_view_post_gallery_activity"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -109,35 +109,6 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.libRG.CustomTextView
|
||||
android:id="@+id/flair_custom_text_view_post_image_activity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:padding="4dp"
|
||||
android:text="@string/flair"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="?attr/font_default"
|
||||
android:fontFamily="?attr/font_family"
|
||||
android:visibility="gone"
|
||||
app:lib_setRadius="6dp"
|
||||
app:lib_setRoundedView="true"
|
||||
app:lib_setShape="rectangle" />
|
||||
|
||||
<com.libRG.CustomTextView
|
||||
android:id="@+id/spoiler_custom_text_view_post_image_activity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:padding="4dp"
|
||||
android:text="@string/spoiler"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="?attr/font_default"
|
||||
android:fontFamily="?attr/font_family"
|
||||
app:lib_setRadius="6dp"
|
||||
app:lib_setRoundedView="true"
|
||||
app:lib_setShape="rectangle" />
|
||||
|
||||
<com.libRG.CustomTextView
|
||||
android:id="@+id/nsfw_custom_text_view_post_image_activity"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -109,35 +109,6 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.libRG.CustomTextView
|
||||
android:id="@+id/flair_custom_text_view_post_link_activity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:padding="4dp"
|
||||
android:text="@string/flair"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="?attr/font_default"
|
||||
android:fontFamily="?attr/font_family"
|
||||
android:visibility="gone"
|
||||
app:lib_setRadius="6dp"
|
||||
app:lib_setRoundedView="true"
|
||||
app:lib_setShape="rectangle" />
|
||||
|
||||
<com.libRG.CustomTextView
|
||||
android:id="@+id/spoiler_custom_text_view_post_link_activity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:padding="4dp"
|
||||
android:text="@string/spoiler"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="?attr/font_default"
|
||||
android:fontFamily="?attr/font_family"
|
||||
app:lib_setRadius="6dp"
|
||||
app:lib_setRoundedView="true"
|
||||
app:lib_setShape="rectangle" />
|
||||
|
||||
<com.libRG.CustomTextView
|
||||
android:id="@+id/nsfw_custom_text_view_post_link_activity"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -109,35 +109,6 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.libRG.CustomTextView
|
||||
android:id="@+id/flair_custom_text_view_post_poll_activity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:padding="4dp"
|
||||
android:text="@string/flair"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="?attr/font_default"
|
||||
android:fontFamily="?attr/font_family"
|
||||
android:visibility="gone"
|
||||
app:lib_setRadius="6dp"
|
||||
app:lib_setRoundedView="true"
|
||||
app:lib_setShape="rectangle" />
|
||||
|
||||
<com.libRG.CustomTextView
|
||||
android:id="@+id/spoiler_custom_text_view_post_poll_activity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:padding="4dp"
|
||||
android:text="@string/spoiler"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="?attr/font_default"
|
||||
android:fontFamily="?attr/font_family"
|
||||
app:lib_setRadius="6dp"
|
||||
app:lib_setRoundedView="true"
|
||||
app:lib_setShape="rectangle" />
|
||||
|
||||
<com.libRG.CustomTextView
|
||||
android:id="@+id/nsfw_custom_text_view_post_poll_activity"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -115,33 +115,6 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.libRG.CustomTextView
|
||||
android:id="@+id/flair_custom_text_view_post_text_activity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:padding="4dp"
|
||||
android:text="@string/flair"
|
||||
android:textSize="?attr/font_default"
|
||||
android:fontFamily="?attr/font_family"
|
||||
android:visibility="gone"
|
||||
app:lib_setRadius="6dp"
|
||||
app:lib_setRoundedView="true"
|
||||
app:lib_setShape="rectangle" />
|
||||
|
||||
<com.libRG.CustomTextView
|
||||
android:id="@+id/spoiler_custom_text_view_post_text_activity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:padding="4dp"
|
||||
android:text="@string/spoiler"
|
||||
android:textSize="?attr/font_default"
|
||||
android:fontFamily="?attr/font_family"
|
||||
app:lib_setRadius="6dp"
|
||||
app:lib_setRoundedView="true"
|
||||
app:lib_setShape="rectangle" />
|
||||
|
||||
<com.libRG.CustomTextView
|
||||
android:id="@+id/nsfw_custom_text_view_post_text_activity"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -109,35 +109,6 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.libRG.CustomTextView
|
||||
android:id="@+id/flair_custom_text_view_post_video_activity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:padding="4dp"
|
||||
android:text="@string/flair"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="?attr/font_default"
|
||||
android:fontFamily="?attr/font_family"
|
||||
android:visibility="gone"
|
||||
app:lib_setRadius="6dp"
|
||||
app:lib_setRoundedView="true"
|
||||
app:lib_setShape="rectangle" />
|
||||
|
||||
<com.libRG.CustomTextView
|
||||
android:id="@+id/spoiler_custom_text_view_post_video_activity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:padding="4dp"
|
||||
android:text="@string/spoiler"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="?attr/font_default"
|
||||
android:fontFamily="?attr/font_family"
|
||||
app:lib_setRadius="6dp"
|
||||
app:lib_setRoundedView="true"
|
||||
app:lib_setShape="rectangle" />
|
||||
|
||||
<com.libRG.CustomTextView
|
||||
android:id="@+id/nsfw_custom_text_view_post_video_activity"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -48,25 +48,6 @@
|
||||
android:focusable="true"
|
||||
android:background="?attr/selectableItemBackground" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/video_type_linear_layout_post_type_bottom_sheet_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingStart="32dp"
|
||||
android:paddingEnd="32dp"
|
||||
android:text="@string/bottom_sheet_post_video"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="?attr/font_default"
|
||||
android:fontFamily="?attr/font_family"
|
||||
android:drawableStart="@drawable/ic_outline_video_24dp"
|
||||
android:drawablePadding="48dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:background="?attr/selectableItemBackground" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/image_type_linear_layout_post_type_bottom_sheet_fragment"
|
||||
android:layout_width="match_parent"
|
||||
@@ -86,44 +67,6 @@
|
||||
android:focusable="true"
|
||||
android:background="?attr/selectableItemBackground" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/gallery_type_linear_layout_post_type_bottom_sheet_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingStart="32dp"
|
||||
android:paddingEnd="32dp"
|
||||
android:text="@string/bottom_sheet_post_gallery"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="?attr/font_default"
|
||||
android:fontFamily="?attr/font_family"
|
||||
android:drawableStart="@drawable/ic_gallery_24dp"
|
||||
android:drawablePadding="48dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:background="?attr/selectableItemBackground" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/poll_type_linear_layout_post_type_bottom_sheet_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingStart="32dp"
|
||||
android:paddingEnd="32dp"
|
||||
android:text="@string/bottom_sheet_post_poll"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="?attr/font_default"
|
||||
android:fontFamily="?attr/font_family"
|
||||
android:drawableStart="@drawable/ic_poll_24dp"
|
||||
android:drawablePadding="48dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:background="?attr/selectableItemBackground" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
@@ -116,6 +116,7 @@
|
||||
<string name="no_users">No users found</string>
|
||||
<string name="no_multi_reddits">No Multireddits found</string>
|
||||
<string name="no_storage_permission">No storage permission to save this file</string>
|
||||
<string name="anonymous_homepage_not_implemented">Anonymous homepage is not implemented yet</string>
|
||||
|
||||
<string name="load_comments_failed">Error loading comments.\nTap to retry.</string>
|
||||
<string name="retry">Retry</string>
|
||||
@@ -149,6 +150,8 @@
|
||||
<string name="online_subscribers_number_detail">Online: %1$,d</string>
|
||||
<string name="cannot_fetch_community_info">Cannot fetch community info</string>
|
||||
<string name="cannot_fetch_user_info">Cannot fetch user info</string>
|
||||
<string name="invalid_response">Invalid response from the server</string>
|
||||
<string name="invalid_username_or_password">Invalid username or password</string>
|
||||
<string name="cannot_fetch_sidebar">Cannot fetch sidebar</string>
|
||||
<string name="cannot_fetch_multireddit">Cannot fetch multireddit info</string>
|
||||
|
||||
@@ -465,7 +468,7 @@
|
||||
<string name="settings_credits_best_rocket_icon_summary">Icon made by Freepik from www.flaticon.com</string>
|
||||
<string name="settings_credits_material_icons_title">Material Icons</string>
|
||||
<string name="settings_open_source_title">Open Source</string>
|
||||
<string name="settings_open_source_summary">Star it on Github if you like this app</string>
|
||||
<string name="settings_open_source_summary">Star it on Codeberg if you like this app</string>
|
||||
<string name="settings_rate_title">Rate on Google Play</string>
|
||||
<string name="settings_rate_summary">Give me a 5-star rating and I will be really happy</string>
|
||||
<string name="settings_email_title">Mastodon</string>
|
||||
@@ -473,7 +476,7 @@
|
||||
<string name="settings_reddit_account_title">Lemmy Account</string>
|
||||
<string name="settings_reddit_account_summary">\@bazsalanszky@lemmy.toldi.eu</string>
|
||||
<string name="settings_community_title">Community</string>
|
||||
<string name="settings_community_summary">r/Infinity_For_Reddit</string>
|
||||
<string name="settings_community_summary">!infinityforlemmy@lemdro.id</string>
|
||||
<string name="settings_share_title">Share</string>
|
||||
<string name="settings_share_summary">Share this app to other people if you enjoy it</string>
|
||||
<string name="settings_privacy_policy_title">Privacy Policy</string>
|
||||
@@ -1336,4 +1339,6 @@
|
||||
<string name="sort_time_3months">3 Months</string>
|
||||
<string name="sort_time_6months">6 Months</string>
|
||||
<string name="sort_time_9months">9 Months</string>
|
||||
<string name="anonymous_account_instance">Anonymous Account Instance</string>
|
||||
<string name="url_cannot_be_null_or_empty">URL cannot be null or empty</string>
|
||||
</resources>
|
||||
|
||||
@@ -21,11 +21,6 @@
|
||||
app:title="@string/settings_open_source_title"
|
||||
app:summary="@string/settings_open_source_summary" />
|
||||
|
||||
<eu.toldi.infinityforlemmy.customviews.CustomFontPreference
|
||||
android:key="rate"
|
||||
app:title="@string/settings_rate_title"
|
||||
app:summary="@string/settings_rate_summary" />
|
||||
|
||||
<eu.toldi.infinityforlemmy.customviews.CustomFontPreference
|
||||
android:key="email"
|
||||
app:title="@string/settings_email_title"
|
||||
|
||||
@@ -87,14 +87,4 @@
|
||||
app:title="@string/settings_about_master_title"
|
||||
app:fragment="eu.toldi.infinityforlemmy.settings.AboutPreferenceFragment" />
|
||||
|
||||
<eu.toldi.infinityforlemmy.customviews.CustomFontPreference
|
||||
android:key="privacy_policy"
|
||||
app:icon="@drawable/ic_outline_privacy_policy_24dp"
|
||||
app:title="@string/settings_privacy_policy_title" />
|
||||
|
||||
<eu.toldi.infinityforlemmy.customviews.CustomFontPreference
|
||||
android:key="reddit_user_agreement"
|
||||
app:icon="@drawable/ic_outline_user_agreement_24dp"
|
||||
app:title="@string/settings_reddit_user_agreement_title" />
|
||||
|
||||
</androidx.preference.PreferenceScreen>
|
||||
@@ -40,8 +40,13 @@
|
||||
app:title="@string/settings_language_title"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
|
||||
<eu.toldi.infinityforlemmy.customviews.CustomFontPreferenceCategory
|
||||
app:title="@string/settings_miscellaneous_dangerous_group_title" />
|
||||
<eu.toldi.infinityforlemmy.customviews.CustomFontEditTextPreference
|
||||
app:defaultValue="https://lemmy.world"
|
||||
app:key="anonymous_account_instance"
|
||||
app:title="@string/anonymous_account_instance"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
|
||||
<eu.toldi.infinityforlemmy.customviews.CustomFontPreferenceCategory app:title="@string/settings_miscellaneous_dangerous_group_title" />
|
||||
|
||||
<eu.toldi.infinityforlemmy.customviews.CustomFontPreference
|
||||
app:icon="@drawable/ic_info_preference_24dp"
|
||||
@@ -54,4 +59,5 @@
|
||||
app:title="@string/settings_post_feed_max_resolution_title"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -1,35 +1,17 @@
|
||||
<p>Infinity is a beautiful, feature-rich app that offers a smooth Reddit browsing experience. It is completely free and ad-less; you can browse Reddit without interruptions or distractions. Built by a passionate university student, Infinity is open source. Please check out, support or contribute to the project at https://github.com/Docile-Alligator/Infinity-For-Reddit!</p>
|
||||
<h1>Infinity for Lemmy</h1>
|
||||
<p>A client for Lemmy, specifically designed for Android and written in Java. This project is a fork of the Infinity for Reddit project, and it is currently in the early stages of development. As such, expect many unfinished features and potential bugs!</p>
|
||||
|
||||
<p>A subreddit for this app is available: https://www.reddit.com/r/Infinity_For_Reddit/</p>
|
||||
|
||||
<p><b>Highlighted features:</b></p>
|
||||
|
||||
<p><b>Lazy mode</b></p>
|
||||
<p>Automatic scrolling of posts enables you to enjoy amazing content without moving your thumb.</p>
|
||||
|
||||
<p><b>Multi-account support</b></p>
|
||||
<p>Switch to different accounts instantaneously.</p>
|
||||
|
||||
<p><b>Night theme</b></p>
|
||||
<p>Beautifully designed night theme</p>
|
||||
|
||||
<p><b>Highlighted feature</b></p>
|
||||
|
||||
<p>Lazy mode: Automatic scrolling of posts enables you to enjoy amazing posts without moving your thumb.</p>
|
||||
|
||||
<p><b>Features:</b></p>
|
||||
<h2>Development Progress</h2>
|
||||
<ul>
|
||||
<li>Browsing posts</li>
|
||||
<li>View comments</li>
|
||||
<li>Expand and collapse comments section</li>
|
||||
<li>Vote posts and comments</li>
|
||||
<li>Save posts</li>
|
||||
<li>Write comments</li>
|
||||
<li>Edit comments and delete comments</li>
|
||||
<li>Submit posts (text, link, image and video)</li>
|
||||
<li>Edit posts (mark and unmark NSFW and spoiler and edit flair) and delete posts</li>
|
||||
<li>See all the subscribed subreddits and followed users</li>
|
||||
<li>View the messages</li>
|
||||
<li>Get notifications of unread messages</li>
|
||||
<li>And much more!</li>
|
||||
</ul>
|
||||
<li>[x] Implementation of basic post browsing feature</li>
|
||||
<li>[x] Support for multiple account handling</li>
|
||||
<li>[x] Functionality for post upvotes/downvotes</li>
|
||||
<li>[x] Functionality to browse comments</li>
|
||||
<li>[ ] Capability for creating a new post</li>
|
||||
<li>[x] Ability to create comments</li>
|
||||
<li>[ ] Elimination of code/string references specific to Reddit</li>
|
||||
<li>[ ] Incorporation of private messaging feature</li>
|
||||
<li>[ ] Feature for saving posts</li>
|
||||
<li>[ ] Account editing function</li>
|
||||
<li>[ ] Multi community view?</li>
|
||||
</ul>
|
||||
|
Before Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 236 KiB After Width: | Height: | Size: 1.1 MiB |
|
Before Width: | Height: | Size: 295 KiB After Width: | Height: | Size: 292 KiB |
|
Before Width: | Height: | Size: 208 KiB After Width: | Height: | Size: 402 KiB |
|
Before Width: | Height: | Size: 431 KiB |
|
Before Width: | Height: | Size: 300 KiB |
|
Before Width: | Height: | Size: 138 KiB |