mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-02-07 07:04:44 +01:00
Compare commits
14 Commits
ea7a4b03ab
...
54fdca4fb6
Author | SHA1 | Date | |
---|---|---|---|
|
54fdca4fb6 | ||
|
5e6a6c6c25 | ||
|
fa6b650f75 | ||
|
5db0e60450 | ||
|
b2fa79da51 | ||
|
098b3c07d2 | ||
|
515dfa65b5 | ||
|
5411aec13f | ||
|
dca840b292 | ||
|
5f1edf8f86 | ||
|
b6d1041691 | ||
|
c75f38f04d | ||
|
5e18119b2d | ||
|
d518293f5a |
@ -72,9 +72,9 @@ Don't forget to give the project a star! Thanks again!
|
|||||||
|
|
||||||
### Translation
|
### Translation
|
||||||
|
|
||||||
You can alos help Eternity by translating it to your native langugage! Translations are done via [Weblate](https://translate.codeberg.org/projects/Eternity/app/)!
|
You can alos help Eternity by translating it to your native langugage! Translations are done via [Weblate](https://translate.codeberg.org/projects/infinity-for-lemmy/app/)!
|
||||||
|
|
||||||
[![Translation](https://translate.codeberg.org/widgets/Eternity/-/app/multi-auto.svg)](https://translate.codeberg.org/engage/Eternity/)
|
[![Translation](https://translate.codeberg.org/widgets/infinity-for-lemmy/-/app/multi-auto.svg)](https://translate.codeberg.org/engage/Eternity/)
|
||||||
|
|
||||||
### Reporting bugs
|
### Reporting bugs
|
||||||
|
|
||||||
|
@ -196,6 +196,7 @@ dependencies {
|
|||||||
def glideVersion = "4.12.0"
|
def glideVersion = "4.12.0"
|
||||||
implementation "com.github.bumptech.glide:glide:$glideVersion"
|
implementation "com.github.bumptech.glide:glide:$glideVersion"
|
||||||
annotationProcessor "com.github.bumptech.glide:compiler:$glideVersion"
|
annotationProcessor "com.github.bumptech.glide:compiler:$glideVersion"
|
||||||
|
implementation "com.github.bumptech.glide:okhttp-integration:$glideVersion"
|
||||||
implementation 'jp.wasabeef:glide-transformations:4.3.0'
|
implementation 'jp.wasabeef:glide-transformations:4.3.0'
|
||||||
implementation 'com.github.santalu:aspect-ratio-imageview:1.0.9'
|
implementation 'com.github.santalu:aspect-ratio-imageview:1.0.9'
|
||||||
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.23'
|
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.23'
|
||||||
|
@ -113,7 +113,7 @@ import eu.toldi.infinityforlemmy.settings.TranslationFragment;
|
|||||||
import eu.toldi.infinityforlemmy.settings.VideoPreferenceFragment;
|
import eu.toldi.infinityforlemmy.settings.VideoPreferenceFragment;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@Component(modules = {AppModule.class, NetworkModule.class})
|
@Component(modules = {AppModule.class, NetworkModule.class, PostEnricherModule.class})
|
||||||
public interface AppComponent {
|
public interface AppComponent {
|
||||||
void inject(MainActivity mainActivity);
|
void inject(MainActivity mainActivity);
|
||||||
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package eu.toldi.infinityforlemmy;
|
package eu.toldi.infinityforlemmy;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
@ -12,9 +10,7 @@ import java.util.concurrent.Executor;
|
|||||||
|
|
||||||
import eu.toldi.infinityforlemmy.apis.GfycatAPI;
|
import eu.toldi.infinityforlemmy.apis.GfycatAPI;
|
||||||
import eu.toldi.infinityforlemmy.apis.RedgifsAPI;
|
import eu.toldi.infinityforlemmy.apis.RedgifsAPI;
|
||||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
|
||||||
import eu.toldi.infinityforlemmy.utils.JSONUtils;
|
import eu.toldi.infinityforlemmy.utils.JSONUtils;
|
||||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Response;
|
import retrofit2.Response;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
@ -44,14 +40,12 @@ public class FetchGfycatOrRedgifsVideoLinks {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void fetchRedgifsVideoLinks(Context context, Executor executor, Handler handler, Retrofit redgifsRetrofit,
|
public static void fetchRedgifsVideoLinks(Executor executor, Handler handler, Retrofit redgifsRetrofit,
|
||||||
SharedPreferences currentAccountSharedPreferences,
|
|
||||||
String gfycatId,
|
String gfycatId,
|
||||||
FetchGfycatOrRedgifsVideoLinksListener fetchGfycatOrRedgifsVideoLinksListener) {
|
FetchGfycatOrRedgifsVideoLinksListener fetchGfycatOrRedgifsVideoLinksListener) {
|
||||||
executor.execute(() -> {
|
executor.execute(() -> {
|
||||||
try {
|
try {
|
||||||
Response<String> response = redgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(APIUtils.getRedgifsOAuthHeader(currentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "")),
|
Response<String> response = redgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(gfycatId).execute();
|
||||||
gfycatId, APIUtils.USER_AGENT).execute();
|
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
parseRedgifsVideoLinks(handler, response.body(), fetchGfycatOrRedgifsVideoLinksListener);
|
parseRedgifsVideoLinks(handler, response.body(), fetchGfycatOrRedgifsVideoLinksListener);
|
||||||
} else {
|
} else {
|
||||||
|
@ -11,6 +11,16 @@ import android.os.Bundle;
|
|||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.lifecycle.LifecycleObserver;
|
||||||
|
import androidx.lifecycle.OnLifecycleEvent;
|
||||||
|
import androidx.lifecycle.ProcessLifecycleOwner;
|
||||||
|
|
||||||
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader;
|
||||||
|
import com.bumptech.glide.load.model.GlideUrl;
|
||||||
import com.evernote.android.state.StateSaver;
|
import com.evernote.android.state.StateSaver;
|
||||||
import com.livefront.bridge.Bridge;
|
import com.livefront.bridge.Bridge;
|
||||||
import com.livefront.bridge.SavedStateHandler;
|
import com.livefront.bridge.SavedStateHandler;
|
||||||
@ -18,15 +28,11 @@ import com.livefront.bridge.SavedStateHandler;
|
|||||||
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.EventBus;
|
||||||
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.lifecycle.Lifecycle;
|
|
||||||
import androidx.lifecycle.LifecycleObserver;
|
|
||||||
import androidx.lifecycle.OnLifecycleEvent;
|
|
||||||
import androidx.lifecycle.ProcessLifecycleOwner;
|
|
||||||
import eu.toldi.infinityforlemmy.activities.LockScreenActivity;
|
import eu.toldi.infinityforlemmy.activities.LockScreenActivity;
|
||||||
import eu.toldi.infinityforlemmy.broadcastreceivers.NetworkWifiStatusReceiver;
|
import eu.toldi.infinityforlemmy.broadcastreceivers.NetworkWifiStatusReceiver;
|
||||||
import eu.toldi.infinityforlemmy.broadcastreceivers.WallpaperChangeReceiver;
|
import eu.toldi.infinityforlemmy.broadcastreceivers.WallpaperChangeReceiver;
|
||||||
@ -38,6 +44,8 @@ import eu.toldi.infinityforlemmy.font.FontFamily;
|
|||||||
import eu.toldi.infinityforlemmy.font.TitleFontFamily;
|
import eu.toldi.infinityforlemmy.font.TitleFontFamily;
|
||||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||||
|
import okhttp3.Call;
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
|
||||||
public class Infinity extends Application implements LifecycleObserver {
|
public class Infinity extends Application implements LifecycleObserver {
|
||||||
public Typeface typeface;
|
public Typeface typeface;
|
||||||
@ -55,6 +63,9 @@ public class Infinity extends Application implements LifecycleObserver {
|
|||||||
@Inject
|
@Inject
|
||||||
@Named("security")
|
@Named("security")
|
||||||
SharedPreferences mSecuritySharedPreferences;
|
SharedPreferences mSecuritySharedPreferences;
|
||||||
|
@Inject
|
||||||
|
@Named("glide")
|
||||||
|
OkHttpClient glideOkHttpClient;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
@ -159,6 +170,9 @@ public class Infinity extends Application implements LifecycleObserver {
|
|||||||
registerReceiver(mNetworkWifiStatusReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
|
registerReceiver(mNetworkWifiStatusReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
|
||||||
|
|
||||||
registerReceiver(new WallpaperChangeReceiver(mSharedPreferences), new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED));
|
registerReceiver(new WallpaperChangeReceiver(mSharedPreferences), new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED));
|
||||||
|
|
||||||
|
OkHttpUrlLoader.Factory factory = new OkHttpUrlLoader.Factory((Call.Factory) glideOkHttpClient);
|
||||||
|
Glide.get(this).getRegistry().replace(GlideUrl.class, InputStream.class, factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
@OnLifecycleEvent(Lifecycle.Event.ON_START)
|
||||||
|
@ -9,6 +9,7 @@ import javax.inject.Singleton;
|
|||||||
|
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
import dagger.Provides;
|
import dagger.Provides;
|
||||||
|
import eu.toldi.infinityforlemmy.apis.RedgifsAPI;
|
||||||
import eu.toldi.infinityforlemmy.apis.StreamableAPI;
|
import eu.toldi.infinityforlemmy.apis.StreamableAPI;
|
||||||
import eu.toldi.infinityforlemmy.comment.LemmyCommentAPI;
|
import eu.toldi.infinityforlemmy.comment.LemmyCommentAPI;
|
||||||
import eu.toldi.infinityforlemmy.post.LemmyPostAPI;
|
import eu.toldi.infinityforlemmy.post.LemmyPostAPI;
|
||||||
@ -37,7 +38,8 @@ abstract class NetworkModule {
|
|||||||
@Provides
|
@Provides
|
||||||
@Named("glide")
|
@Named("glide")
|
||||||
@Singleton
|
@Singleton
|
||||||
static OkHttpClient provideGlideOkHttp(@Named("base") OkHttpClient baseOkHttp) {
|
static OkHttpClient provideGlideOkHttp(@Named("base") OkHttpClient baseOkHttp,
|
||||||
|
@Named("RedgifsAccessTokenAuthenticator") Interceptor redGifsAuthenticator) {
|
||||||
return baseOkHttp.newBuilder()
|
return baseOkHttp.newBuilder()
|
||||||
.addInterceptor(chain -> chain.proceed(
|
.addInterceptor(chain -> chain.proceed(
|
||||||
chain.request()
|
chain.request()
|
||||||
@ -45,6 +47,7 @@ abstract class NetworkModule {
|
|||||||
.header("User-Agent", APIUtils.USER_AGENT)
|
.header("User-Agent", APIUtils.USER_AGENT)
|
||||||
.build()
|
.build()
|
||||||
))
|
))
|
||||||
|
.addInterceptor(redGifsAuthenticator)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,6 +181,12 @@ abstract class NetworkModule {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
static RedgifsAPI provideRedgifsAPI(@Named("redgifs") Retrofit redgifsRetrofit) {
|
||||||
|
return redgifsRetrofit.create(RedgifsAPI.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Named("imgur")
|
@Named("imgur")
|
||||||
@Singleton
|
@Singleton
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
package eu.toldi.infinityforlemmy;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import dagger.Module;
|
||||||
|
import dagger.Provides;
|
||||||
|
import dagger.multibindings.IntoSet;
|
||||||
|
import eu.toldi.infinityforlemmy.apis.RedgifsAPI;
|
||||||
|
import eu.toldi.infinityforlemmy.post.enrich.CompositePostEnricher;
|
||||||
|
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
|
||||||
|
import eu.toldi.infinityforlemmy.post.enrich.RedGifsPostEnricher;
|
||||||
|
|
||||||
|
@Module
|
||||||
|
abstract class PostEnricherModule {
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@IntoSet
|
||||||
|
static PostEnricher provideRedGifsPostEnricher(RedgifsAPI redgifsAPI) {
|
||||||
|
return new RedGifsPostEnricher(redgifsAPI);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
static PostEnricher providePostEnricher(Set<PostEnricher> postEnrichers) {
|
||||||
|
return new CompositePostEnricher(postEnrichers);
|
||||||
|
}
|
||||||
|
}
|
@ -14,7 +14,6 @@ import java.util.Map;
|
|||||||
import eu.toldi.infinityforlemmy.apis.RedgifsAPI;
|
import eu.toldi.infinityforlemmy.apis.RedgifsAPI;
|
||||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||||
import okhttp3.Headers;
|
|
||||||
import okhttp3.Interceptor;
|
import okhttp3.Interceptor;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
@ -22,6 +21,8 @@ import retrofit2.Retrofit;
|
|||||||
import retrofit2.converter.scalars.ScalarsConverterFactory;
|
import retrofit2.converter.scalars.ScalarsConverterFactory;
|
||||||
|
|
||||||
public class RedgifsAccessTokenAuthenticator implements Interceptor {
|
public class RedgifsAccessTokenAuthenticator implements Interceptor {
|
||||||
|
private static final String REDGIFS_HOST = "redgifs.com";
|
||||||
|
|
||||||
private SharedPreferences mCurrentAccountSharedPreferences;
|
private SharedPreferences mCurrentAccountSharedPreferences;
|
||||||
|
|
||||||
public RedgifsAccessTokenAuthenticator(SharedPreferences currentAccountSharedPreferences) {
|
public RedgifsAccessTokenAuthenticator(SharedPreferences currentAccountSharedPreferences) {
|
||||||
@ -60,7 +61,17 @@ public class RedgifsAccessTokenAuthenticator implements Interceptor {
|
|||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Response intercept(@NonNull Chain chain) throws IOException {
|
public Response intercept(@NonNull Chain chain) throws IOException {
|
||||||
Response response = chain.proceed(chain.request());
|
if (!chain.request().url().host().endsWith(REDGIFS_HOST)) {
|
||||||
|
return chain.proceed(chain.request());
|
||||||
|
}
|
||||||
|
|
||||||
|
String currentAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "");
|
||||||
|
Response response = chain.proceed(
|
||||||
|
chain.request().newBuilder()
|
||||||
|
.addHeader(APIUtils.AUTHORIZATION_KEY, APIUtils.AUTHORIZATION_BASE + currentAccessToken)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
if (response.code() == 401 || response.code() == 400) {
|
if (response.code() == 401 || response.code() == 400) {
|
||||||
String accessTokenHeader = response.request().header(APIUtils.AUTHORIZATION_KEY);
|
String accessTokenHeader = response.request().header(APIUtils.AUTHORIZATION_KEY);
|
||||||
if (accessTokenHeader == null) {
|
if (accessTokenHeader == null) {
|
||||||
@ -74,13 +85,21 @@ public class RedgifsAccessTokenAuthenticator implements Interceptor {
|
|||||||
String newAccessToken = refreshAccessToken();
|
String newAccessToken = refreshAccessToken();
|
||||||
if (!newAccessToken.equals("")) {
|
if (!newAccessToken.equals("")) {
|
||||||
response.close();
|
response.close();
|
||||||
return chain.proceed(response.request().newBuilder().headers(Headers.of(APIUtils.getRedgifsOAuthHeader(newAccessToken))).build());
|
return chain.proceed(
|
||||||
|
chain.request().newBuilder()
|
||||||
|
.addHeader(APIUtils.AUTHORIZATION_KEY, APIUtils.AUTHORIZATION_BASE + newAccessToken)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
response.close();
|
response.close();
|
||||||
return chain.proceed(response.request().newBuilder().headers(Headers.of(APIUtils.getRedgifsOAuthHeader(accessTokenFromSharedPreferences))).build());
|
return chain.proceed(
|
||||||
|
chain.request().newBuilder()
|
||||||
|
.addHeader(APIUtils.AUTHORIZATION_KEY, APIUtils.AUTHORIZATION_BASE + accessTokenFromSharedPreferences)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package eu.toldi.infinityforlemmy;
|
package eu.toldi.infinityforlemmy;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import eu.toldi.infinityforlemmy.network.SortTypeConverterFactory;
|
import eu.toldi.infinityforlemmy.network.SortTypeConverterFactory;
|
||||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||||
|
import okhttp3.Interceptor;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
import retrofit2.adapter.guava.GuavaCallAdapterFactory;
|
import retrofit2.adapter.guava.GuavaCallAdapterFactory;
|
||||||
@ -12,8 +15,14 @@ public class RetrofitHolder {
|
|||||||
|
|
||||||
private Retrofit retrofit;
|
private Retrofit retrofit;
|
||||||
private OkHttpClient okHttpClient;
|
private OkHttpClient okHttpClient;
|
||||||
|
|
||||||
|
private OkHttpClient okHttpClientBase;
|
||||||
private String baseURL = APIUtils.API_BASE_URI;
|
private String baseURL = APIUtils.API_BASE_URI;
|
||||||
|
|
||||||
|
private String accessToken = null;
|
||||||
|
|
||||||
|
private Interceptor oAuthInterceptor;
|
||||||
|
|
||||||
public Retrofit getRetrofit() {
|
public Retrofit getRetrofit() {
|
||||||
return retrofit;
|
return retrofit;
|
||||||
}
|
}
|
||||||
@ -33,6 +42,7 @@ public class RetrofitHolder {
|
|||||||
|
|
||||||
public RetrofitHolder(OkHttpClient okHttpClient) {
|
public RetrofitHolder(OkHttpClient okHttpClient) {
|
||||||
this.okHttpClient = okHttpClient;
|
this.okHttpClient = okHttpClient;
|
||||||
|
this.okHttpClientBase = okHttpClient;
|
||||||
this.retrofit = createRetrofit(okHttpClient, APIUtils.API_BASE_URI);
|
this.retrofit = createRetrofit(okHttpClient, APIUtils.API_BASE_URI);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,4 +56,18 @@ public class RetrofitHolder {
|
|||||||
.addConverterFactory(GsonConverterFactory.create())
|
.addConverterFactory(GsonConverterFactory.create())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAccessToken(String accessToken) {
|
||||||
|
this.accessToken = accessToken;
|
||||||
|
OkHttpClient.Builder builder = okHttpClientBase.newBuilder();
|
||||||
|
Log.d("RetrofitHolder", "Access token changed");
|
||||||
|
if (accessToken != null && !accessToken.equals("")) {
|
||||||
|
Log.i("RetrofitHolder", "Setting access token interceptor");
|
||||||
|
oAuthInterceptor = APIUtils.getOAuthInterceptor(accessToken);
|
||||||
|
builder.addInterceptor(oAuthInterceptor);
|
||||||
|
}
|
||||||
|
okHttpClient = builder.build();
|
||||||
|
retrofit = createRetrofit(okHttpClient, baseURL);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -69,15 +69,15 @@ public class SortType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum Time {
|
public enum Time {
|
||||||
HOUR("TopHour", "Top Hour"),
|
HOUR("hour", "Hour"),
|
||||||
SIX_HOURS("TopSixHour", "Top Six Hours"),
|
SIX_HOURS("SixHour", "Six Hours"),
|
||||||
TWELVE_HOURS("TopTwelveHour", "Top Twelve Hours"),
|
TWELVE_HOURS("TwelveHour", "Twelve Hours"),
|
||||||
DAY("day", "Day"),
|
DAY("day", "Day"),
|
||||||
WEEK("week", "Week"),
|
WEEK("week", "Week"),
|
||||||
MONTH("month", "Month"),
|
MONTH("month", "Month"),
|
||||||
THREE_MONTHS("TopThreeMonth", "Top Three Months"),
|
THREE_MONTHS("ThreeMonths", "Three Months"),
|
||||||
SIX_MONTHS("TopSixMonth", "Top Six Months"),
|
SIX_MONTHS("SixMonths", "Six Months"),
|
||||||
NINE_MONTHS("TopNineMonth", "Top Nine Months"),
|
NINE_MONTHS("NineMonths", "Nine Months"),
|
||||||
YEAR("year", "Year"),
|
YEAR("year", "Year"),
|
||||||
ALL("all", "All Time");
|
ALL("all", "All Time");
|
||||||
|
|
||||||
@ -88,5 +88,14 @@ public class SortType {
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
this.fullName = fullName;
|
this.fullName = fullName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Time fromValue(String value) {
|
||||||
|
for (Time time : values()) {
|
||||||
|
if (time.value.equalsIgnoreCase(value)) {
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -283,7 +283,7 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
|
|||||||
PostFragment fragment = new PostFragment();
|
PostFragment fragment = new PostFragment();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_USER);
|
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_USER);
|
||||||
bundle.putString(PostFragment.EXTRA_USER_NAME, mAccountName);
|
bundle.putString(PostFragment.EXTRA_USER_NAME, mAccountQualifiedName);
|
||||||
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_SAVED);
|
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_SAVED);
|
||||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||||
@ -293,7 +293,7 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
|
|||||||
}
|
}
|
||||||
CommentsListingFragment fragment = new CommentsListingFragment();
|
CommentsListingFragment fragment = new CommentsListingFragment();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString(CommentsListingFragment.EXTRA_USERNAME, mAccountName);
|
bundle.putString(CommentsListingFragment.EXTRA_USERNAME, mAccountQualifiedName);
|
||||||
bundle.putString(CommentsListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
bundle.putString(CommentsListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
bundle.putString(CommentsListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
bundle.putString(CommentsListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||||
bundle.putBoolean(CommentsListingFragment.EXTRA_ARE_SAVED_COMMENTS, true);
|
bundle.putBoolean(CommentsListingFragment.EXTRA_ARE_SAVED_COMMENTS, true);
|
||||||
|
@ -159,8 +159,17 @@ public class CreateMultiRedditActivity extends BaseActivity {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a list of community qualified names seperated by a comma
|
||||||
|
StringBuilder subredditList = new StringBuilder();
|
||||||
|
String prefix = "";
|
||||||
|
for (SubredditWithSelection s : mSubreddits) {
|
||||||
|
subredditList.append(prefix);
|
||||||
|
prefix = ",";
|
||||||
|
subredditList.append(s.getQualifiedName());
|
||||||
|
}
|
||||||
|
|
||||||
CreateMultiReddit.anonymousCreateMultiReddit(mExecutor, new Handler(), mRedditDataRoomDatabase,
|
CreateMultiReddit.anonymousCreateMultiReddit(mExecutor, new Handler(), mRedditDataRoomDatabase,
|
||||||
"/user/" + mAccountName + "/m/" + nameEditText.getText().toString(),
|
mAccountName, subredditList.toString(),
|
||||||
nameEditText.getText().toString(), descriptionEditText.getText().toString(),
|
nameEditText.getText().toString(), descriptionEditText.getText().toString(),
|
||||||
mSubreddits, new CreateMultiReddit.CreateMultiRedditListener() {
|
mSubreddits, new CreateMultiReddit.CreateMultiRedditListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -36,6 +36,7 @@ import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
|||||||
import eu.toldi.infinityforlemmy.post.FetchPost;
|
import eu.toldi.infinityforlemmy.post.FetchPost;
|
||||||
import eu.toldi.infinityforlemmy.post.ObjectResolver;
|
import eu.toldi.infinityforlemmy.post.ObjectResolver;
|
||||||
import eu.toldi.infinityforlemmy.post.Post;
|
import eu.toldi.infinityforlemmy.post.Post;
|
||||||
|
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
|
||||||
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
|
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
|
||||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||||
|
|
||||||
@ -83,6 +84,9 @@ public class LinkResolverActivity extends AppCompatActivity {
|
|||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
PostEnricher postEnricher;
|
||||||
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
|
|
||||||
private Uri getRedditUriByPath(String path) {
|
private Uri getRedditUriByPath(String path) {
|
||||||
@ -102,6 +106,9 @@ public class LinkResolverActivity extends AppCompatActivity {
|
|||||||
if (mAccessToken != null) {
|
if (mAccessToken != null) {
|
||||||
String instance = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_INSTANCE, null);
|
String instance = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_INSTANCE, null);
|
||||||
mRetrofit.setBaseURL(instance);
|
mRetrofit.setBaseURL(instance);
|
||||||
|
if (mCurrentAccountSharedPreferences.getBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, true)) {
|
||||||
|
mRetrofit.setAccessToken(mAccessToken);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Uri uri = getIntent().getData();
|
Uri uri = getIntent().getData();
|
||||||
@ -214,7 +221,7 @@ public class LinkResolverActivity extends AppCompatActivity {
|
|||||||
URL baseURL = new URL(mRetrofit.getBaseURL());
|
URL baseURL = new URL(mRetrofit.getBaseURL());
|
||||||
if (baseURL.getHost().equalsIgnoreCase(uri.getHost())) {
|
if (baseURL.getHost().equalsIgnoreCase(uri.getHost())) {
|
||||||
local = true;
|
local = true;
|
||||||
FetchPost.fetchPost(mExecutor, new Handler(), mRetrofit.getRetrofit(), segments.get(segments.size() - 1), mAccessToken, new FetchPost.FetchPostListener() {
|
FetchPost.fetchPost(mExecutor, new Handler(), mRetrofit.getRetrofit(), segments.get(segments.size() - 1), mAccessToken, postEnricher, new FetchPost.FetchPostListener() {
|
||||||
@Override
|
@Override
|
||||||
public void fetchPostSuccess(Post post) {
|
public void fetchPostSuccess(Post post) {
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ import android.os.Bundle;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Patterns;
|
|
||||||
import android.view.InflateException;
|
import android.view.InflateException;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@ -180,6 +179,7 @@ public class LoginActivity extends BaseActivity {
|
|||||||
try {
|
try {
|
||||||
JSONObject responseJSON = new JSONObject(accountResponse);
|
JSONObject responseJSON = new JSONObject(accountResponse);
|
||||||
String accessToken = responseJSON.getString("jwt");
|
String accessToken = responseJSON.getString("jwt");
|
||||||
|
mRetrofit.setAccessToken(null);
|
||||||
|
|
||||||
FetchMyInfo.fetchAccountInfo(mRetrofit.getRetrofit(), mRedditDataRoomDatabase, username,
|
FetchMyInfo.fetchAccountInfo(mRetrofit.getRetrofit(), mRedditDataRoomDatabase, username,
|
||||||
accessToken, new FetchMyInfo.FetchMyInfoListener() {
|
accessToken, new FetchMyInfo.FetchMyInfoListener() {
|
||||||
@ -189,13 +189,23 @@ public class LoginActivity extends BaseActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onFetchSiteInfoSuccess(SiteInfo siteInfo) {
|
public void onFetchSiteInfoSuccess(SiteInfo siteInfo) {
|
||||||
boolean canDownvote = siteInfo.isEnable_downvotes();
|
boolean canDownvote = siteInfo.isEnable_downvotes();
|
||||||
ParseAndInsertNewAccount.parseAndInsertNewAccount(mExecutor, new Handler(), name,display_name, accessToken, profileImageUrl, bannerImageUrl, authCode, finalInstance,canDownvote, mRedditDataRoomDatabase.accountDao(),
|
ParseAndInsertNewAccount.parseAndInsertNewAccount(mExecutor, new Handler(), name, display_name, accessToken, profileImageUrl, bannerImageUrl, authCode, finalInstance, canDownvote, mRedditDataRoomDatabase.accountDao(),
|
||||||
() -> {
|
() -> {
|
||||||
Intent resultIntent = new Intent();
|
Intent resultIntent = new Intent();
|
||||||
setResult(Activity.RESULT_OK, resultIntent);
|
setResult(Activity.RESULT_OK, resultIntent);
|
||||||
finish();
|
finish();
|
||||||
});
|
});
|
||||||
mCurrentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.CAN_DOWNVOTE, canDownvote).apply();
|
mCurrentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.CAN_DOWNVOTE, canDownvote).apply();
|
||||||
|
String[] version = siteInfo.getVersion().split("\\.");
|
||||||
|
if (version.length > 0) {
|
||||||
|
Log.d("SwitchAccount", "Lemmy Version: " + version[0] + "." + version[1]);
|
||||||
|
int majorVersion = Integer.parseInt(version[0]);
|
||||||
|
int minorVersion = Integer.parseInt(version[1]);
|
||||||
|
if (majorVersion > 0 || (majorVersion == 0 && minorVersion >= 19)) {
|
||||||
|
mRetrofit.setAccessToken(accessToken);
|
||||||
|
mCurrentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, true).apply();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -336,11 +336,14 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
fragmentManager = getSupportFragmentManager();
|
fragmentManager = getSupportFragmentManager();
|
||||||
|
|
||||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
|
if (mCurrentAccountSharedPreferences.getBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, true)) {
|
||||||
|
mRetrofit.setAccessToken(mAccessToken);
|
||||||
|
}
|
||||||
|
|
||||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
|
mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
|
||||||
String instance = (mAccessToken == null) ? mSharedPreferences.getString(SharedPreferencesUtils.ANONYMOUS_ACCOUNT_INSTANCE, APIUtils.API_BASE_URI) : 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) {
|
if (instance != null) {
|
||||||
mRetrofit.setBaseURL(instance);
|
mRetrofit.setBaseURL(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1511,7 +1514,12 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
if (i == EditorInfo.IME_ACTION_DONE) {
|
if (i == EditorInfo.IME_ACTION_DONE) {
|
||||||
Utils.hideKeyboard(this);
|
Utils.hideKeyboard(this);
|
||||||
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
|
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
|
||||||
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, thingEditText.getText().toString());
|
String communityName = thingEditText.getText().toString();
|
||||||
|
if (communityName.startsWith("!")) {
|
||||||
|
communityName = communityName.substring(1);
|
||||||
|
}
|
||||||
|
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName);
|
||||||
|
|
||||||
startActivity(subredditIntent);
|
startActivity(subredditIntent);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1569,7 +1577,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
-> {
|
-> {
|
||||||
Utils.hideKeyboard(this);
|
Utils.hideKeyboard(this);
|
||||||
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
|
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
|
||||||
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, thingEditText.getText().toString());
|
String communityName = thingEditText.getText().toString();
|
||||||
|
if (communityName.startsWith("!")) {
|
||||||
|
communityName = communityName.substring(1);
|
||||||
|
}
|
||||||
|
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName);
|
||||||
startActivity(subredditIntent);
|
startActivity(subredditIntent);
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
|
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
|
||||||
@ -1590,7 +1602,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
if (i == EditorInfo.IME_ACTION_DONE) {
|
if (i == EditorInfo.IME_ACTION_DONE) {
|
||||||
Utils.hideKeyboard(this);
|
Utils.hideKeyboard(this);
|
||||||
Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
|
Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
|
||||||
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, thingEditText.getText().toString());
|
String qualifiedName = thingEditText.getText().toString();
|
||||||
|
if (qualifiedName.startsWith("@")) {
|
||||||
|
qualifiedName = qualifiedName.substring(1);
|
||||||
|
}
|
||||||
|
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, qualifiedName);
|
||||||
startActivity(userIntent);
|
startActivity(userIntent);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1603,7 +1619,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
-> {
|
-> {
|
||||||
Utils.hideKeyboard(this);
|
Utils.hideKeyboard(this);
|
||||||
Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
|
Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
|
||||||
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, thingEditText.getText().toString());
|
String qualifiedName = thingEditText.getText().toString();
|
||||||
|
if (qualifiedName.startsWith("@")) {
|
||||||
|
qualifiedName = qualifiedName.substring(1);
|
||||||
|
}
|
||||||
|
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, qualifiedName);
|
||||||
startActivity(userIntent);
|
startActivity(userIntent);
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
|
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
|
||||||
|
@ -67,6 +67,7 @@ import eu.toldi.infinityforlemmy.SaveComment;
|
|||||||
import eu.toldi.infinityforlemmy.SaveThing;
|
import eu.toldi.infinityforlemmy.SaveThing;
|
||||||
import eu.toldi.infinityforlemmy.SortType;
|
import eu.toldi.infinityforlemmy.SortType;
|
||||||
import eu.toldi.infinityforlemmy.SortTypeSelectionCallback;
|
import eu.toldi.infinityforlemmy.SortTypeSelectionCallback;
|
||||||
|
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||||
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
||||||
import eu.toldi.infinityforlemmy.asynctasks.SwitchAccount;
|
import eu.toldi.infinityforlemmy.asynctasks.SwitchAccount;
|
||||||
import eu.toldi.infinityforlemmy.comment.Comment;
|
import eu.toldi.infinityforlemmy.comment.Comment;
|
||||||
@ -81,6 +82,7 @@ import eu.toldi.infinityforlemmy.post.HistoryPostPagingSource;
|
|||||||
import eu.toldi.infinityforlemmy.post.ParsePost;
|
import eu.toldi.infinityforlemmy.post.ParsePost;
|
||||||
import eu.toldi.infinityforlemmy.post.Post;
|
import eu.toldi.infinityforlemmy.post.Post;
|
||||||
import eu.toldi.infinityforlemmy.post.PostPagingSource;
|
import eu.toldi.infinityforlemmy.post.PostPagingSource;
|
||||||
|
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
|
||||||
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
|
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
|
||||||
import eu.toldi.infinityforlemmy.readpost.ReadPost;
|
import eu.toldi.infinityforlemmy.readpost.ReadPost;
|
||||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||||
@ -151,6 +153,8 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
|
|||||||
@Inject
|
@Inject
|
||||||
@Named("glide")
|
@Named("glide")
|
||||||
OkHttpClient okHttpClient;
|
OkHttpClient okHttpClient;
|
||||||
|
@Inject
|
||||||
|
PostEnricher postEnricher;
|
||||||
@State
|
@State
|
||||||
ArrayList<Post> posts;
|
ArrayList<Post> posts;
|
||||||
@State
|
@State
|
||||||
@ -530,69 +534,38 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
|
|||||||
Handler handler = new Handler(Looper.getMainLooper());
|
Handler handler = new Handler(Looper.getMainLooper());
|
||||||
|
|
||||||
if (postType != HistoryPostPagingSource.TYPE_READ_POSTS) {
|
if (postType != HistoryPostPagingSource.TYPE_READ_POSTS) {
|
||||||
|
int nextPage = posts.size() / 25 + 1;
|
||||||
|
|
||||||
mExecutor.execute(() -> {
|
mExecutor.execute(() -> {
|
||||||
RedditAPI api = (mAccessToken == null ? mRetrofit.getRetrofit() : mOauthRetrofit).create(RedditAPI.class);
|
LemmyAPI api = mRetrofit.getRetrofit().create(LemmyAPI.class);
|
||||||
Call<String> call;
|
Call<String> call;
|
||||||
String afterKey = posts.isEmpty() ? null : posts.get(posts.size() - 1).getFullName();
|
|
||||||
switch (postType) {
|
switch (postType) {
|
||||||
case PostPagingSource.TYPE_SUBREDDIT:
|
case PostPagingSource.TYPE_SUBREDDIT:
|
||||||
if (mAccessToken == null) {
|
call = api.getPosts(null, sortType.value, nextPage, 25, null, post.getSubredditNamePrefixed(), false, mAccessToken);
|
||||||
call = api.getSubredditBestPosts(subredditName, sortType, sortTime, afterKey);
|
|
||||||
} else {
|
|
||||||
call = api.getSubredditBestPostsOauth(subredditName, sortType,
|
|
||||||
sortTime, afterKey, APIUtils.getOAuthHeader(mAccessToken));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case PostPagingSource.TYPE_USER:
|
case PostPagingSource.TYPE_USER:
|
||||||
if (mAccessToken == null) {
|
call = api.getUserPosts(username, sortType.value, nextPage, 25, false, mAccessToken);
|
||||||
call = api.getUserPosts(username, afterKey, sortType, sortTime);
|
|
||||||
} else {
|
|
||||||
call = api.getUserPostsOauth(username, userWhere, afterKey, sortType,
|
|
||||||
sortTime, APIUtils.getOAuthHeader(mAccessToken));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case PostPagingSource.TYPE_SEARCH:
|
case PostPagingSource.TYPE_SEARCH:
|
||||||
if (subredditName == null) {
|
call = api.search(query, null, subredditName, null, "Post", sortType.value, "All", nextPage, 25, mAccessToken);
|
||||||
if (mAccessToken == null) {
|
|
||||||
call = api.searchPosts(query, afterKey, sortType, sortTime,
|
|
||||||
trendingSource);
|
|
||||||
} else {
|
|
||||||
call = api.searchPostsOauth(query, afterKey, sortType,
|
|
||||||
sortTime, trendingSource, APIUtils.getOAuthHeader(mAccessToken));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (mAccessToken == null) {
|
|
||||||
call = api.searchPostsInSpecificSubreddit(subredditName, query,
|
|
||||||
sortType, sortTime, afterKey);
|
|
||||||
} else {
|
|
||||||
call = api.searchPostsInSpecificSubredditOauth(subredditName, query,
|
|
||||||
sortType, sortTime, afterKey,
|
|
||||||
APIUtils.getOAuthHeader(mAccessToken));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case PostPagingSource.TYPE_MULTI_REDDIT:
|
case PostPagingSource.TYPE_MULTI_REDDIT:
|
||||||
if (mAccessToken == null) {
|
// TODO: Implement multi community
|
||||||
call = api.getMultiRedditPosts(multiPath, afterKey, sortTime);
|
|
||||||
} else {
|
|
||||||
call = api.getMultiRedditPostsOauth(multiPath, afterKey,
|
|
||||||
sortTime, APIUtils.getOAuthHeader(mAccessToken));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE:
|
case PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE:
|
||||||
//case PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT
|
// TODO: Implement anonymous front page
|
||||||
call = api.getSubredditBestPosts(subredditName, sortType, sortTime, afterKey);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
call = api.getBestPosts(sortType, sortTime, afterKey,
|
String type = (subredditName.equals("all")) ? "All" : (subredditName.equals("local")) ? "Local" : "Subscribed";
|
||||||
APIUtils.getOAuthHeader(mAccessToken));
|
call = api.getPosts(type, sortType.value, nextPage, 25, null, null, false, mAccessToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Response<String> response = call.execute();
|
Response<String> response = call.execute();
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
String responseString = response.body();
|
String responseString = response.body();
|
||||||
LinkedHashSet<Post> newPosts = ParsePost.parsePostsSync(responseString, -1, postFilter, readPostList);
|
LinkedHashSet<Post> newPosts = ParsePost.parsePostsSync(responseString, -1, postFilter, readPostList, postEnricher);
|
||||||
if (newPosts == null) {
|
if (newPosts == null) {
|
||||||
handler.post(() -> {
|
handler.post(() -> {
|
||||||
loadingMorePostsStatus = LoadingMorePostsStatus.NO_MORE_POSTS;
|
loadingMorePostsStatus = LoadingMorePostsStatus.NO_MORE_POSTS;
|
||||||
@ -674,7 +647,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
|
|||||||
Response<String> response = historyPosts.execute();
|
Response<String> response = historyPosts.execute();
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
String responseString = response.body();
|
String responseString = response.body();
|
||||||
LinkedHashSet<Post> newPosts = ParsePost.parsePostsSync(responseString, -1, postFilter, null);
|
LinkedHashSet<Post> newPosts = ParsePost.parsePostsSync(responseString, -1, postFilter, null, postEnricher);
|
||||||
if (newPosts == null || newPosts.isEmpty()) {
|
if (newPosts == null || newPosts.isEmpty()) {
|
||||||
handler.post(() -> {
|
handler.post(() -> {
|
||||||
loadingMorePostsStatus = LoadingMorePostsStatus.NO_MORE_POSTS;
|
loadingMorePostsStatus = LoadingMorePostsStatus.NO_MORE_POSTS;
|
||||||
|
@ -1518,7 +1518,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
if (i == EditorInfo.IME_ACTION_DONE) {
|
if (i == EditorInfo.IME_ACTION_DONE) {
|
||||||
Utils.hideKeyboard(this);
|
Utils.hideKeyboard(this);
|
||||||
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
|
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
|
||||||
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString());
|
String communityName = thingEditText.getText().toString();
|
||||||
|
if (communityName.startsWith("!")) {
|
||||||
|
communityName = communityName.substring(1);
|
||||||
|
}
|
||||||
|
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName);
|
||||||
startActivity(subredditIntent);
|
startActivity(subredditIntent);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1576,7 +1580,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
-> {
|
-> {
|
||||||
Utils.hideKeyboard(this);
|
Utils.hideKeyboard(this);
|
||||||
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
|
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
|
||||||
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString());
|
String communityName = thingEditText.getText().toString();
|
||||||
|
if (communityName.startsWith("!")) {
|
||||||
|
communityName = communityName.substring(1);
|
||||||
|
}
|
||||||
|
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName);
|
||||||
startActivity(subredditIntent);
|
startActivity(subredditIntent);
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
|
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
|
||||||
@ -1597,7 +1605,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
if (i == EditorInfo.IME_ACTION_DONE) {
|
if (i == EditorInfo.IME_ACTION_DONE) {
|
||||||
Utils.hideKeyboard(this);
|
Utils.hideKeyboard(this);
|
||||||
Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
|
Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
|
||||||
userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString());
|
String qualifiedName = thingEditText.getText().toString();
|
||||||
|
if (qualifiedName.startsWith("@")) {
|
||||||
|
qualifiedName = qualifiedName.substring(1);
|
||||||
|
}
|
||||||
|
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, qualifiedName);
|
||||||
startActivity(userIntent);
|
startActivity(userIntent);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1610,7 +1622,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
-> {
|
-> {
|
||||||
Utils.hideKeyboard(this);
|
Utils.hideKeyboard(this);
|
||||||
Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
|
Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
|
||||||
userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString());
|
String qualifiedName = thingEditText.getText().toString();
|
||||||
|
if (qualifiedName.startsWith("@")) {
|
||||||
|
qualifiedName = qualifiedName.substring(1);
|
||||||
|
}
|
||||||
|
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, qualifiedName);
|
||||||
startActivity(userIntent);
|
startActivity(userIntent);
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
|
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
|
||||||
|
@ -1514,7 +1514,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
|||||||
if (i == EditorInfo.IME_ACTION_DONE) {
|
if (i == EditorInfo.IME_ACTION_DONE) {
|
||||||
Utils.hideKeyboard(this);
|
Utils.hideKeyboard(this);
|
||||||
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
|
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
|
||||||
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString());
|
String communityName = thingEditText.getText().toString();
|
||||||
|
if (communityName.startsWith("!")) {
|
||||||
|
communityName = communityName.substring(1);
|
||||||
|
}
|
||||||
|
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName);
|
||||||
startActivity(subredditIntent);
|
startActivity(subredditIntent);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1572,7 +1576,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
|||||||
-> {
|
-> {
|
||||||
Utils.hideKeyboard(this);
|
Utils.hideKeyboard(this);
|
||||||
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
|
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
|
||||||
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString());
|
String communityName = thingEditText.getText().toString();
|
||||||
|
if (communityName.startsWith("!")) {
|
||||||
|
communityName = communityName.substring(1);
|
||||||
|
}
|
||||||
|
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName);
|
||||||
startActivity(subredditIntent);
|
startActivity(subredditIntent);
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
|
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
|
||||||
@ -1593,7 +1601,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
|||||||
if (i == EditorInfo.IME_ACTION_DONE) {
|
if (i == EditorInfo.IME_ACTION_DONE) {
|
||||||
Utils.hideKeyboard(this);
|
Utils.hideKeyboard(this);
|
||||||
Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
|
Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
|
||||||
userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString());
|
String userName = thingEditText.getText().toString();
|
||||||
|
if (userName.startsWith("@")) {
|
||||||
|
userName = userName.substring(1);
|
||||||
|
}
|
||||||
|
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, userName);
|
||||||
startActivity(userIntent);
|
startActivity(userIntent);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1606,7 +1618,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
|||||||
-> {
|
-> {
|
||||||
Utils.hideKeyboard(this);
|
Utils.hideKeyboard(this);
|
||||||
Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
|
Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
|
||||||
userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString());
|
String userName = thingEditText.getText().toString();
|
||||||
|
if (userName.startsWith("@")) {
|
||||||
|
userName = userName.substring(1);
|
||||||
|
}
|
||||||
|
userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, userName);
|
||||||
startActivity(userIntent);
|
startActivity(userIntent);
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
|
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
|
||||||
|
@ -108,6 +108,7 @@ import eu.toldi.infinityforlemmy.font.TitleFontFamily;
|
|||||||
import eu.toldi.infinityforlemmy.font.TitleFontStyle;
|
import eu.toldi.infinityforlemmy.font.TitleFontStyle;
|
||||||
import eu.toldi.infinityforlemmy.post.FetchPost;
|
import eu.toldi.infinityforlemmy.post.FetchPost;
|
||||||
import eu.toldi.infinityforlemmy.post.Post;
|
import eu.toldi.infinityforlemmy.post.Post;
|
||||||
|
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
|
||||||
import eu.toldi.infinityforlemmy.services.DownloadMediaService;
|
import eu.toldi.infinityforlemmy.services.DownloadMediaService;
|
||||||
import eu.toldi.infinityforlemmy.services.DownloadRedditVideoService;
|
import eu.toldi.infinityforlemmy.services.DownloadRedditVideoService;
|
||||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||||
@ -222,10 +223,6 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
|
|||||||
@Named("default")
|
@Named("default")
|
||||||
SharedPreferences mSharedPreferences;
|
SharedPreferences mSharedPreferences;
|
||||||
|
|
||||||
@Inject
|
|
||||||
@Named("current_account")
|
|
||||||
SharedPreferences mCurrentAccountSharedPreferences;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
|
|
||||||
@ -235,6 +232,9 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
|
|||||||
@Inject
|
@Inject
|
||||||
SimpleCache mSimpleCache;
|
SimpleCache mSimpleCache;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
PostEnricher postEnricher;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -756,8 +756,8 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
FetchGfycatOrRedgifsVideoLinks.fetchRedgifsVideoLinks(this, mExecutor, new Handler(), redgifsRetrofit,
|
FetchGfycatOrRedgifsVideoLinks.fetchRedgifsVideoLinks(mExecutor, new Handler(), redgifsRetrofit,
|
||||||
mCurrentAccountSharedPreferences, gfycatId, new FetchGfycatOrRedgifsVideoLinks.FetchGfycatOrRedgifsVideoLinksListener() {
|
gfycatId, new FetchGfycatOrRedgifsVideoLinks.FetchGfycatOrRedgifsVideoLinksListener() {
|
||||||
@Override
|
@Override
|
||||||
public void success(String webm, String mp4) {
|
public void success(String webm, String mp4) {
|
||||||
progressBar.setVisibility(View.GONE);
|
progressBar.setVisibility(View.GONE);
|
||||||
@ -791,7 +791,7 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
|
|||||||
int commentsIndex = segments.lastIndexOf("comments");
|
int commentsIndex = segments.lastIndexOf("comments");
|
||||||
String postId = segments.get(commentsIndex + 1);
|
String postId = segments.get(commentsIndex + 1);
|
||||||
FetchPost.fetchPost(mExecutor, new Handler(), retrofit.getRetrofit(), postId, null,
|
FetchPost.fetchPost(mExecutor, new Handler(), retrofit.getRetrofit(), postId, null,
|
||||||
new FetchPost.FetchPostListener() {
|
postEnricher, new FetchPost.FetchPostListener() {
|
||||||
@Override
|
@Override
|
||||||
public void fetchPostSuccess(Post post) {
|
public void fetchPostSuccess(Post post) {
|
||||||
if (post.isGfycat()) {
|
if (post.isGfycat()) {
|
||||||
|
@ -139,7 +139,6 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
|||||||
private BaseActivity mActivity;
|
private BaseActivity mActivity;
|
||||||
private HistoryPostFragment mFragment;
|
private HistoryPostFragment mFragment;
|
||||||
private SharedPreferences mSharedPreferences;
|
private SharedPreferences mSharedPreferences;
|
||||||
private SharedPreferences mCurrentAccountSharedPreferences;
|
|
||||||
private Executor mExecutor;
|
private Executor mExecutor;
|
||||||
private Retrofit retrofit;
|
private Retrofit retrofit;
|
||||||
private Retrofit mGfycatRetrofit;
|
private Retrofit mGfycatRetrofit;
|
||||||
@ -227,7 +226,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
|||||||
Retrofit gfycatRetrofit, Retrofit redgifsRetrofit, Provider<StreamableAPI> streambleApiProvider,
|
Retrofit gfycatRetrofit, Retrofit redgifsRetrofit, Provider<StreamableAPI> streambleApiProvider,
|
||||||
CustomThemeWrapper customThemeWrapper, Locale locale,
|
CustomThemeWrapper customThemeWrapper, Locale locale,
|
||||||
String accessToken, String accountName, int postType, int postLayout, boolean displaySubredditName,
|
String accessToken, String accountName, int postType, int postLayout, boolean displaySubredditName,
|
||||||
SharedPreferences sharedPreferences, SharedPreferences currentAccountSharedPreferences,
|
SharedPreferences sharedPreferences,
|
||||||
SharedPreferences nsfwAndSpoilerSharedPreferences,
|
SharedPreferences nsfwAndSpoilerSharedPreferences,
|
||||||
ExoCreator exoCreator, Callback callback) {
|
ExoCreator exoCreator, Callback callback) {
|
||||||
super(DIFF_CALLBACK);
|
super(DIFF_CALLBACK);
|
||||||
@ -235,7 +234,6 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
|||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
mFragment = fragment;
|
mFragment = fragment;
|
||||||
mSharedPreferences = sharedPreferences;
|
mSharedPreferences = sharedPreferences;
|
||||||
mCurrentAccountSharedPreferences = currentAccountSharedPreferences;
|
|
||||||
mExecutor = executor;
|
mExecutor = executor;
|
||||||
retrofit = oauthRetrofit;
|
retrofit = oauthRetrofit;
|
||||||
mGfycatRetrofit = gfycatRetrofit;
|
mGfycatRetrofit = gfycatRetrofit;
|
||||||
@ -698,7 +696,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
|||||||
if ((post.isGfycat() || post.isRedgifs()) && !post.isLoadGfycatOrStreamableVideoSuccess()) {
|
if ((post.isGfycat() || post.isRedgifs()) && !post.isLoadGfycatOrStreamableVideoSuccess()) {
|
||||||
((PostVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall =
|
((PostVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall =
|
||||||
post.isGfycat() ? mGfycatRetrofit.create(GfycatAPI.class).getGfycatData(post.getGfycatId()) :
|
post.isGfycat() ? mGfycatRetrofit.create(GfycatAPI.class).getGfycatData(post.getGfycatId()) :
|
||||||
mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(APIUtils.getRedgifsOAuthHeader(mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "")), post.getGfycatId(), APIUtils.USER_AGENT);
|
mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(post.getGfycatId());
|
||||||
FetchGfycatOrRedgifsVideoLinks.fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(mExecutor, new Handler(),
|
FetchGfycatOrRedgifsVideoLinks.fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(mExecutor, new Handler(),
|
||||||
((PostVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall,
|
((PostVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall,
|
||||||
post.isGfycat(), mAutomaticallyTryRedgifs,
|
post.isGfycat(), mAutomaticallyTryRedgifs,
|
||||||
@ -875,7 +873,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
|
|||||||
if ((post.isGfycat() || post.isRedgifs()) && !post.isLoadGfycatOrStreamableVideoSuccess()) {
|
if ((post.isGfycat() || post.isRedgifs()) && !post.isLoadGfycatOrStreamableVideoSuccess()) {
|
||||||
((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall =
|
((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall =
|
||||||
post.isGfycat() ? mGfycatRetrofit.create(GfycatAPI.class).getGfycatData(post.getGfycatId()) :
|
post.isGfycat() ? mGfycatRetrofit.create(GfycatAPI.class).getGfycatData(post.getGfycatId()) :
|
||||||
mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(APIUtils.getRedgifsOAuthHeader(mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "")), post.getGfycatId(), APIUtils.USER_AGENT);
|
mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(post.getGfycatId());
|
||||||
FetchGfycatOrRedgifsVideoLinks.fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(mExecutor, new Handler(),
|
FetchGfycatOrRedgifsVideoLinks.fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(mExecutor, new Handler(),
|
||||||
((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall,
|
((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall,
|
||||||
post.isGfycat(), mAutomaticallyTryRedgifs,
|
post.isGfycat(), mAutomaticallyTryRedgifs,
|
||||||
|
@ -698,7 +698,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
|
|||||||
if (mPost.isGfycat() || mPost.isRedgifs() && !mPost.isLoadGfycatOrStreamableVideoSuccess()) {
|
if (mPost.isGfycat() || mPost.isRedgifs() && !mPost.isLoadGfycatOrStreamableVideoSuccess()) {
|
||||||
((PostDetailVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall =
|
((PostDetailVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall =
|
||||||
mPost.isGfycat() ? mGfycatRetrofit.create(GfycatAPI.class).getGfycatData(mPost.getGfycatId()) :
|
mPost.isGfycat() ? mGfycatRetrofit.create(GfycatAPI.class).getGfycatData(mPost.getGfycatId()) :
|
||||||
mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(APIUtils.getRedgifsOAuthHeader(mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "")), mPost.getGfycatId(), APIUtils.USER_AGENT);
|
mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(mPost.getGfycatId());
|
||||||
FetchGfycatOrRedgifsVideoLinks.fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(mExecutor, new Handler(),
|
FetchGfycatOrRedgifsVideoLinks.fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(mExecutor, new Handler(),
|
||||||
((PostDetailVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall,
|
((PostDetailVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall,
|
||||||
mPost.isGfycat(), mAutomaticallyTryRedgifs,
|
mPost.isGfycat(), mAutomaticallyTryRedgifs,
|
||||||
|
@ -787,7 +787,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
|||||||
if ((post.isGfycat() || post.isRedgifs()) && !post.isLoadGfycatOrStreamableVideoSuccess()) {
|
if ((post.isGfycat() || post.isRedgifs()) && !post.isLoadGfycatOrStreamableVideoSuccess()) {
|
||||||
((PostVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall =
|
((PostVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall =
|
||||||
post.isGfycat() ? mGfycatRetrofit.create(GfycatAPI.class).getGfycatData(post.getGfycatId()) :
|
post.isGfycat() ? mGfycatRetrofit.create(GfycatAPI.class).getGfycatData(post.getGfycatId()) :
|
||||||
mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(APIUtils.getRedgifsOAuthHeader(mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "")), post.getGfycatId(), APIUtils.USER_AGENT);
|
mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(post.getGfycatId());
|
||||||
FetchGfycatOrRedgifsVideoLinks.fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(mExecutor, new Handler(),
|
FetchGfycatOrRedgifsVideoLinks.fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(mExecutor, new Handler(),
|
||||||
((PostVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall,
|
((PostVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall,
|
||||||
post.isGfycat(), mAutomaticallyTryRedgifs,
|
post.isGfycat(), mAutomaticallyTryRedgifs,
|
||||||
@ -979,7 +979,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
|||||||
if ((post.isGfycat() || post.isRedgifs()) && !post.isLoadGfycatOrStreamableVideoSuccess()) {
|
if ((post.isGfycat() || post.isRedgifs()) && !post.isLoadGfycatOrStreamableVideoSuccess()) {
|
||||||
((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall =
|
((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall =
|
||||||
post.isGfycat() ? mGfycatRetrofit.create(GfycatAPI.class).getGfycatData(post.getGfycatId()) :
|
post.isGfycat() ? mGfycatRetrofit.create(GfycatAPI.class).getGfycatData(post.getGfycatId()) :
|
||||||
mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(APIUtils.getRedgifsOAuthHeader(mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "")), post.getGfycatId(), APIUtils.USER_AGENT);
|
mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(post.getGfycatId());
|
||||||
FetchGfycatOrRedgifsVideoLinks.fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(mExecutor, new Handler(),
|
FetchGfycatOrRedgifsVideoLinks.fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(mExecutor, new Handler(),
|
||||||
((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall,
|
((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall,
|
||||||
post.isGfycat(), mAutomaticallyTryRedgifs,
|
post.isGfycat(), mAutomaticallyTryRedgifs,
|
||||||
|
@ -158,7 +158,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
|
|||||||
mFavoriteSubscribedSubredditData.size() + 3 : 1;
|
mFavoriteSubscribedSubredditData.size() + 3 : 1;
|
||||||
} else {
|
} else {
|
||||||
offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
|
offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
|
||||||
mFavoriteSubscribedSubredditData.size() + 2 : 1;
|
mFavoriteSubscribedSubredditData.size() + 2 : 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
|
offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
|
||||||
@ -301,7 +301,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (itemClickListener != null) {
|
if (itemClickListener != null) {
|
||||||
return mSubscribedSubredditData.size() > 0 ? mSubscribedSubredditData.size() + 1 : 0;
|
return (hasClearSelectionRow) ? mSubscribedSubredditData.size() + 1 : mSubscribedSubredditData.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
return mSubscribedSubredditData.size();
|
return mSubscribedSubredditData.size();
|
||||||
|
@ -101,7 +101,16 @@ public interface LemmyAPI {
|
|||||||
Call<String> postDelete(@Body DeletePostDTO params);
|
Call<String> postDelete(@Body DeletePostDTO params);
|
||||||
|
|
||||||
@GET("api/v3/user")
|
@GET("api/v3/user")
|
||||||
ListenableFuture<Response<String>> getUserPosts(
|
ListenableFuture<Response<String>> getUserPostsListenableFuture(
|
||||||
|
@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/user")
|
||||||
|
Call<String> getUserPosts(
|
||||||
@Query("username") String username,
|
@Query("username") String username,
|
||||||
@Query("sort") String sort,
|
@Query("sort") String sort,
|
||||||
@Query("page") Integer page,
|
@Query("page") Integer page,
|
||||||
@ -129,7 +138,19 @@ public interface LemmyAPI {
|
|||||||
);
|
);
|
||||||
|
|
||||||
@GET("api/v3/post/list")
|
@GET("api/v3/post/list")
|
||||||
ListenableFuture<Response<String>> getPosts(
|
ListenableFuture<Response<String>> getPostsListenableFuture(
|
||||||
|
@Query("type_") String type_,
|
||||||
|
@Query("sort") String sort,
|
||||||
|
@Query("page") Integer page,
|
||||||
|
@Query("limit") Integer limit,
|
||||||
|
@Query("community_id") Integer community_id,
|
||||||
|
@Query("community_name") String community_name,
|
||||||
|
@Query("saved_only") Boolean saved_only,
|
||||||
|
@Query("auth") String auth
|
||||||
|
);
|
||||||
|
|
||||||
|
@GET("api/v3/post/list")
|
||||||
|
Call<String> getPosts(
|
||||||
@Query("type_") String type_,
|
@Query("type_") String type_,
|
||||||
@Query("sort") String sort,
|
@Query("sort") String sort,
|
||||||
@Query("page") Integer page,
|
@Query("page") Integer page,
|
||||||
|
@ -6,14 +6,16 @@ import retrofit2.Call;
|
|||||||
import retrofit2.http.FieldMap;
|
import retrofit2.http.FieldMap;
|
||||||
import retrofit2.http.FormUrlEncoded;
|
import retrofit2.http.FormUrlEncoded;
|
||||||
import retrofit2.http.GET;
|
import retrofit2.http.GET;
|
||||||
import retrofit2.http.HeaderMap;
|
|
||||||
import retrofit2.http.POST;
|
import retrofit2.http.POST;
|
||||||
import retrofit2.http.Path;
|
import retrofit2.http.Path;
|
||||||
import retrofit2.http.Query;
|
import retrofit2.http.Query;
|
||||||
|
|
||||||
public interface RedgifsAPI {
|
public interface RedgifsAPI {
|
||||||
@GET("/v2/gifs/{id}")
|
@GET("/v2/gifs/{id}")
|
||||||
Call<String> getRedgifsData(@HeaderMap Map<String, String> headers, @Path("id") String id, @Query("user-agent") String userAgent);
|
Call<String> getRedgifsData(@Path("id") String id);
|
||||||
|
|
||||||
|
@GET("/v2/gifs")
|
||||||
|
Call<String> getRedgifsMultipleData(@Query("ids") String ids);
|
||||||
|
|
||||||
@FormUrlEncoded
|
@FormUrlEncoded
|
||||||
@POST("/v2/oauth/client")
|
@POST("/v2/oauth/client")
|
||||||
|
@ -2,6 +2,7 @@ package eu.toldi.infinityforlemmy.asynctasks;
|
|||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
@ -25,18 +26,31 @@ public class SwitchAccount {
|
|||||||
.putString(SharedPreferencesUtils.ACCESS_TOKEN, account.getAccessToken())
|
.putString(SharedPreferencesUtils.ACCESS_TOKEN, account.getAccessToken())
|
||||||
.putString(SharedPreferencesUtils.ACCOUNT_NAME, account.getDisplay_name())
|
.putString(SharedPreferencesUtils.ACCOUNT_NAME, account.getDisplay_name())
|
||||||
.putString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, account.getAccountName())
|
.putString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, account.getAccountName())
|
||||||
.putString(SharedPreferencesUtils.ACCOUNT_INSTANCE,account.getInstance_url())
|
.putString(SharedPreferencesUtils.ACCOUNT_INSTANCE, account.getInstance_url())
|
||||||
|
.putBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, false)
|
||||||
.putString(SharedPreferencesUtils.ACCOUNT_IMAGE_URL, account.getProfileImageUrl()).apply();
|
.putString(SharedPreferencesUtils.ACCOUNT_IMAGE_URL, account.getProfileImageUrl()).apply();
|
||||||
retrofitHolder.setBaseURL(account.getInstance_url());
|
retrofitHolder.setBaseURL(account.getInstance_url());
|
||||||
|
retrofitHolder.setAccessToken(null);
|
||||||
FetchSiteInfo.fetchSiteInfo(retrofitHolder.getRetrofit(), account.getAccessToken(), new FetchSiteInfo.FetchSiteInfoListener() {
|
FetchSiteInfo.fetchSiteInfo(retrofitHolder.getRetrofit(), account.getAccessToken(), new FetchSiteInfo.FetchSiteInfoListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onFetchSiteInfoSuccess(SiteInfo siteInfo) {
|
public void onFetchSiteInfoSuccess(SiteInfo siteInfo) {
|
||||||
boolean canDownvote = siteInfo.isEnable_downvotes();
|
boolean canDownvote = siteInfo.isEnable_downvotes();
|
||||||
currentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.CAN_DOWNVOTE, canDownvote).apply();
|
currentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.CAN_DOWNVOTE, canDownvote).apply();
|
||||||
|
String[] version = siteInfo.getVersion().split("\\.");
|
||||||
|
if (version.length > 0) {
|
||||||
|
Log.d("SwitchAccount", "Lemmy Version: " + version[0] + "." + version[1]);
|
||||||
|
int majorVersion = Integer.parseInt(version[0]);
|
||||||
|
int minorVersion = Integer.parseInt(version[1]);
|
||||||
|
if (majorVersion > 0 || (majorVersion == 0 && minorVersion >= 19)) {
|
||||||
|
retrofitHolder.setAccessToken(account.getAccessToken());
|
||||||
|
currentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, true).apply();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFetchSiteInfoFailed() {
|
public void onFetchSiteInfoFailed() {
|
||||||
|
Log.e("SwitchAccount", "Failed to fetch site info");
|
||||||
currentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.CAN_DOWNVOTE, true).apply();
|
currentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.CAN_DOWNVOTE, true).apply();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -124,6 +124,7 @@ import eu.toldi.infinityforlemmy.events.ShowThumbnailOnTheRightInCompactLayoutEv
|
|||||||
import eu.toldi.infinityforlemmy.post.HistoryPostPagingSource;
|
import eu.toldi.infinityforlemmy.post.HistoryPostPagingSource;
|
||||||
import eu.toldi.infinityforlemmy.post.HistoryPostViewModel;
|
import eu.toldi.infinityforlemmy.post.HistoryPostViewModel;
|
||||||
import eu.toldi.infinityforlemmy.post.Post;
|
import eu.toldi.infinityforlemmy.post.Post;
|
||||||
|
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
|
||||||
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
|
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
|
||||||
import eu.toldi.infinityforlemmy.postfilter.PostFilterUsage;
|
import eu.toldi.infinityforlemmy.postfilter.PostFilterUsage;
|
||||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||||
@ -178,9 +179,6 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato
|
|||||||
@Named("default")
|
@Named("default")
|
||||||
SharedPreferences mSharedPreferences;
|
SharedPreferences mSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
@Named("current_account")
|
|
||||||
SharedPreferences mCurrentAccountSharedPreferences;
|
|
||||||
@Inject
|
|
||||||
@Named("post_layout")
|
@Named("post_layout")
|
||||||
SharedPreferences mPostLayoutSharedPreferences;
|
SharedPreferences mPostLayoutSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
@ -198,6 +196,8 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato
|
|||||||
ExoCreator mExoCreator;
|
ExoCreator mExoCreator;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
|
@Inject
|
||||||
|
PostEnricher postEnricher;
|
||||||
private RequestManager mGlide;
|
private RequestManager mGlide;
|
||||||
private BaseActivity activity;
|
private BaseActivity activity;
|
||||||
private LinearLayoutManagerBugFixed mLinearLayoutManager;
|
private LinearLayoutManagerBugFixed mLinearLayoutManager;
|
||||||
@ -383,7 +383,7 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato
|
|||||||
mAdapter = new HistoryPostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit.getRetrofit(), mGfycatRetrofit,
|
mAdapter = new HistoryPostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit.getRetrofit(), mGfycatRetrofit,
|
||||||
mRedgifsRetrofit, mStreamableApiProvider, mCustomThemeWrapper, locale,
|
mRedgifsRetrofit, mStreamableApiProvider, mCustomThemeWrapper, locale,
|
||||||
accessToken, accountName, postType, postLayout, true,
|
accessToken, accountName, postType, postLayout, true,
|
||||||
mSharedPreferences, mCurrentAccountSharedPreferences, mNsfwAndSpoilerSharedPreferences,
|
mSharedPreferences, mNsfwAndSpoilerSharedPreferences,
|
||||||
mExoCreator, new HistoryPostRecyclerViewAdapter.Callback() {
|
mExoCreator, new HistoryPostRecyclerViewAdapter.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void typeChipClicked(int filter) {
|
public void typeChipClicked(int filter) {
|
||||||
@ -654,15 +654,10 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initializeAndBindPostViewModel(String accessToken) {
|
private void initializeAndBindPostViewModel(String accessToken) {
|
||||||
if (postType == HistoryPostPagingSource.TYPE_READ_POSTS) {
|
mHistoryPostViewModel = new ViewModelProvider(HistoryPostFragment.this, new HistoryPostViewModel.Factory(mExecutor,
|
||||||
mHistoryPostViewModel = new ViewModelProvider(HistoryPostFragment.this, new HistoryPostViewModel.Factory(mExecutor,
|
accessToken == null ? mRetrofit.getRetrofit() : mOauthRetrofit, mRedditDataRoomDatabase, accessToken,
|
||||||
accessToken == null ? mRetrofit.getRetrofit() : mOauthRetrofit, mRedditDataRoomDatabase, accessToken,
|
accountName, mSharedPreferences, HistoryPostPagingSource.TYPE_READ_POSTS, postFilter, postEnricher))
|
||||||
accountName, mSharedPreferences, HistoryPostPagingSource.TYPE_READ_POSTS, postFilter)).get(HistoryPostViewModel.class);
|
.get(HistoryPostViewModel.class);
|
||||||
} else {
|
|
||||||
mHistoryPostViewModel = new ViewModelProvider(HistoryPostFragment.this, new HistoryPostViewModel.Factory(mExecutor,
|
|
||||||
accessToken == null ? mRetrofit.getRetrofit() : mOauthRetrofit, mRedditDataRoomDatabase, accessToken,
|
|
||||||
accountName, mSharedPreferences, HistoryPostPagingSource.TYPE_READ_POSTS, postFilter)).get(HistoryPostViewModel.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
bindPostViewModel();
|
bindPostViewModel();
|
||||||
}
|
}
|
||||||
|
@ -135,6 +135,7 @@ import eu.toldi.infinityforlemmy.events.ShowThumbnailOnTheRightInCompactLayoutEv
|
|||||||
import eu.toldi.infinityforlemmy.post.Post;
|
import eu.toldi.infinityforlemmy.post.Post;
|
||||||
import eu.toldi.infinityforlemmy.post.PostPagingSource;
|
import eu.toldi.infinityforlemmy.post.PostPagingSource;
|
||||||
import eu.toldi.infinityforlemmy.post.PostViewModel;
|
import eu.toldi.infinityforlemmy.post.PostViewModel;
|
||||||
|
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
|
||||||
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
|
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
|
||||||
import eu.toldi.infinityforlemmy.postfilter.PostFilterUsage;
|
import eu.toldi.infinityforlemmy.postfilter.PostFilterUsage;
|
||||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||||
@ -222,6 +223,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
ExoCreator mExoCreator;
|
ExoCreator mExoCreator;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
|
@Inject
|
||||||
|
PostEnricher postEnricher;
|
||||||
private RequestManager mGlide;
|
private RequestManager mGlide;
|
||||||
private BaseActivity activity;
|
private BaseActivity activity;
|
||||||
private LinearLayoutManagerBugFixed mLinearLayoutManager;
|
private LinearLayoutManagerBugFixed mLinearLayoutManager;
|
||||||
@ -533,17 +536,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + subredditName,
|
sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + subredditName,
|
||||||
mSharedPreferences.getString(SharedPreferencesUtils.SUBREDDIT_DEFAULT_SORT_TIME, SortType.Time.ALL.name()));
|
mSharedPreferences.getString(SharedPreferencesUtils.SUBREDDIT_DEFAULT_SORT_TIME, SortType.Time.ALL.name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sortType = newSortType(sort, sortTime);
|
||||||
|
|
||||||
boolean displaySubredditName = subredditName != null && (subredditName.equals("local") || subredditName.equals("all"));
|
boolean displaySubredditName = subredditName != null && (subredditName.equals("local") || subredditName.equals("all"));
|
||||||
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, defaultPostLayout);
|
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, defaultPostLayout);
|
||||||
SortType.Type st = SortType.Type.fromValue(sort);
|
|
||||||
st = st == null ? SortType.Type.HOT : st;
|
|
||||||
if (sortTime != null) {
|
|
||||||
st = SortType.Type.fromValue(sortTime);
|
|
||||||
st = st == null ? SortType.Type.TOP_ALL : st;
|
|
||||||
sortType = new SortType(st);
|
|
||||||
} else {
|
|
||||||
sortType = new SortType(st);
|
|
||||||
}
|
|
||||||
|
|
||||||
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit,
|
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit,
|
||||||
mRedgifsRetrofit, mStreamableApiProvider, mCustomThemeWrapper, locale,
|
mRedgifsRetrofit, mStreamableApiProvider, mCustomThemeWrapper, locale,
|
||||||
@ -607,16 +605,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath,
|
sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath,
|
||||||
SortType.Time.ALL.name());
|
SortType.Time.ALL.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sortType = newSortType(sort, sortTime);
|
||||||
|
|
||||||
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiRedditPath,
|
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiRedditPath,
|
||||||
defaultPostLayout);
|
defaultPostLayout);
|
||||||
|
|
||||||
SortType.Type st = SortType.Type.fromValue(sort);
|
|
||||||
st = st == null ? SortType.Type.HOT : st;
|
|
||||||
if (sortTime != null) {
|
|
||||||
sortType = new SortType(st, SortType.Time.valueOf(sortTime));
|
|
||||||
} else {
|
|
||||||
sortType = new SortType(st);
|
|
||||||
}
|
|
||||||
|
|
||||||
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit,
|
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit,
|
||||||
mRedgifsRetrofit, mStreamableApiProvider, mCustomThemeWrapper, locale,
|
mRedgifsRetrofit, mStreamableApiProvider, mCustomThemeWrapper, locale,
|
||||||
@ -674,17 +668,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
|
|
||||||
String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username,
|
String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username,
|
||||||
mSharedPreferences.getString(SharedPreferencesUtils.USER_DEFAULT_SORT_TYPE, SortType.Type.NEW.name()));
|
mSharedPreferences.getString(SharedPreferencesUtils.USER_DEFAULT_SORT_TYPE, SortType.Type.NEW.name()));
|
||||||
SortType.Type st = SortType.Type.fromValue(sort);
|
String sortTime = null;
|
||||||
st = st == null ? SortType.Type.NEW : st;
|
|
||||||
if (sort.equalsIgnoreCase(SortType.Type.TOP.value)) {
|
if (sort.equalsIgnoreCase(SortType.Type.TOP.value)) {
|
||||||
String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username,
|
sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username,
|
||||||
mSharedPreferences.getString(SharedPreferencesUtils.USER_DEFAULT_SORT_TIME, SortType.Time.ALL.name()));
|
mSharedPreferences.getString(SharedPreferencesUtils.USER_DEFAULT_SORT_TIME, SortType.Time.ALL.name()));
|
||||||
st = SortType.Type.fromValue(sortTime);
|
|
||||||
st = st == null ? SortType.Type.NEW : st;
|
|
||||||
sortType = new SortType(st);
|
|
||||||
} else {
|
|
||||||
sortType = new SortType(st);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sortType = newSortType(sort, sortTime);
|
||||||
|
|
||||||
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + username, defaultPostLayout);
|
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + username, defaultPostLayout);
|
||||||
|
|
||||||
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit,
|
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit,
|
||||||
@ -741,14 +732,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
subredditName = getArguments().getString(EXTRA_NAME);
|
subredditName = getArguments().getString(EXTRA_NAME);
|
||||||
|
|
||||||
String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + "-", SortType.Type.HOT.name());
|
String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + "-", SortType.Type.HOT.name());
|
||||||
SortType.Type st = SortType.Type.fromValue(sort);
|
String sortTime = null;
|
||||||
st = st == null ? SortType.Type.NEW : st;
|
|
||||||
if (sort.equals(SortType.Type.TOP.name())) {
|
if (sort.equals(SortType.Type.TOP.name())) {
|
||||||
String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + "-", SortType.Time.ALL.name());
|
sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + "-", SortType.Time.ALL.name());
|
||||||
sortType = new SortType(st, SortType.Time.valueOf(sortTime));
|
|
||||||
} else {
|
|
||||||
sortType = new SortType(st);
|
|
||||||
}
|
}
|
||||||
|
sortType = newSortType(sort, sortTime);
|
||||||
|
|
||||||
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout);
|
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout);
|
||||||
|
|
||||||
@ -803,14 +791,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
nameOfUsage = multiRedditPath;
|
nameOfUsage = multiRedditPath;
|
||||||
|
|
||||||
String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath, SortType.Type.HOT.name());
|
String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath, SortType.Type.HOT.name());
|
||||||
SortType.Type st = SortType.Type.fromValue(sort);
|
String sortTime = null;
|
||||||
st = st == null ? SortType.Type.NEW : st;
|
|
||||||
if (sort.equals(SortType.Type.TOP.name())) {
|
if (sort.equals(SortType.Type.TOP.name())) {
|
||||||
String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath, SortType.Time.ALL.name());
|
sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath, SortType.Time.ALL.name());
|
||||||
sortType = new SortType(st, SortType.Time.valueOf(sortTime));
|
|
||||||
} else {
|
|
||||||
sortType = new SortType(st);
|
|
||||||
}
|
}
|
||||||
|
sortType = newSortType(sort, sortTime);
|
||||||
|
|
||||||
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiRedditPath, defaultPostLayout);
|
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiRedditPath, defaultPostLayout);
|
||||||
|
|
||||||
@ -863,14 +848,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
nameOfUsage = PostFilterUsage.NO_USAGE;
|
nameOfUsage = PostFilterUsage.NO_USAGE;
|
||||||
subredditName = getArguments().getString(EXTRA_NAME);
|
subredditName = getArguments().getString(EXTRA_NAME);
|
||||||
String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, SortType.Type.ACTIVE.name());
|
String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, SortType.Type.ACTIVE.name());
|
||||||
SortType.Type st = SortType.Type.fromValue(sort);
|
String sortTime = null;
|
||||||
st = st == null ? SortType.Type.NEW : st;
|
|
||||||
if (sort.equals(SortType.Type.TOP.name())) {
|
if (sort.equals(SortType.Type.TOP.name())) {
|
||||||
String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_BEST_POST, SortType.Time.ALL.name());
|
sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_BEST_POST, SortType.Time.ALL.name());
|
||||||
sortType = new SortType(st, SortType.Time.valueOf(sortTime));
|
|
||||||
} else {
|
|
||||||
sortType = new SortType(st);
|
|
||||||
}
|
}
|
||||||
|
sortType = newSortType(sort, sortTime);
|
||||||
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout);
|
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout);
|
||||||
|
|
||||||
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit,
|
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit,
|
||||||
@ -988,7 +970,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
this.postFilter = postFilter;
|
this.postFilter = postFilter;
|
||||||
postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false);
|
postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false);
|
||||||
this.concatenatedSubredditNames = concatenatedSubredditNames;
|
this.concatenatedSubredditNames = concatenatedSubredditNames;
|
||||||
showErrorView(R.string.anonymous_homepage_not_implemented);
|
//showErrorView(R.string.anonymous_homepage_not_implemented);
|
||||||
|
initializeAndBindPostViewModelForAnonymous(concatenatedSubredditNames);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -1030,7 +1013,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
if (activity != null && !activity.isFinishing() && !activity.isDestroyed() && !isDetached()) {
|
if (activity != null && !activity.isFinishing() && !activity.isDestroyed() && !isDetached()) {
|
||||||
postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false);
|
postFilter.allowNSFW = !mSharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_NSFW_FOREVER, false) && mNsfwAndSpoilerSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_BASE, false);
|
||||||
this.concatenatedSubredditNames = concatenatedSubredditNames;
|
this.concatenatedSubredditNames = concatenatedSubredditNames;
|
||||||
showErrorView(R.string.anonymous_homepage_not_implemented);
|
//showErrorView(R.string.anonymous_homepage_not_implemented);
|
||||||
|
initializeAndBindPostViewModelForAnonymous(concatenatedSubredditNames);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -1221,30 +1205,36 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
mRetrofit, accessToken,
|
mRetrofit, accessToken,
|
||||||
accountName, mSharedPreferences,
|
accountName, mSharedPreferences,
|
||||||
mPostFeedScrolledPositionSharedPreferences, mPostHistorySharedPreferences, subredditName,
|
mPostFeedScrolledPositionSharedPreferences, mPostHistorySharedPreferences, subredditName,
|
||||||
query, trendingSource, postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
|
query, trendingSource, postType, sortType, postFilter, readPosts, postEnricher))
|
||||||
|
.get(PostViewModel.class);
|
||||||
} else if (postType == PostPagingSource.TYPE_SUBREDDIT) {
|
} else if (postType == PostPagingSource.TYPE_SUBREDDIT) {
|
||||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||||
mRetrofit, accessToken,
|
mRetrofit, accessToken,
|
||||||
accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
|
accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
|
||||||
mPostHistorySharedPreferences, subredditName, postType, sortType, postFilter, readPosts))
|
mPostHistorySharedPreferences, subredditName, postType, sortType, postFilter, readPosts,
|
||||||
|
postEnricher))
|
||||||
.get(PostViewModel.class);
|
.get(PostViewModel.class);
|
||||||
} else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) {
|
} else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) {
|
||||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||||
mRetrofit, accessToken,
|
mRetrofit, accessToken,
|
||||||
accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
|
accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
|
||||||
mPostHistorySharedPreferences, multiRedditPath, postType, sortType, postFilter, readPosts))
|
mPostHistorySharedPreferences, multiRedditPath, postType, sortType, postFilter, readPosts,
|
||||||
|
postEnricher))
|
||||||
.get(PostViewModel.class);
|
.get(PostViewModel.class);
|
||||||
} else if (postType == PostPagingSource.TYPE_USER) {
|
} else if (postType == PostPagingSource.TYPE_USER) {
|
||||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||||
mRetrofit, accessToken,
|
mRetrofit, accessToken,
|
||||||
accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
|
accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
|
||||||
mPostHistorySharedPreferences, username, postType, sortType, postFilter, where, readPosts))
|
mPostHistorySharedPreferences, username, postType, sortType, postFilter, where, readPosts,
|
||||||
|
postEnricher))
|
||||||
.get(PostViewModel.class);
|
.get(PostViewModel.class);
|
||||||
} else {
|
} else {
|
||||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||||
mRetrofit, accessToken,
|
mRetrofit, accessToken,
|
||||||
accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
|
accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
|
||||||
mPostHistorySharedPreferences, postType, sortType, postFilter, readPosts, subredditName)).get(PostViewModel.class);
|
mPostHistorySharedPreferences, postType, sortType, postFilter, readPosts, subredditName,
|
||||||
|
postEnricher))
|
||||||
|
.get(PostViewModel.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
bindPostViewModel();
|
bindPostViewModel();
|
||||||
@ -1256,26 +1246,27 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||||
mRetrofit, null, accountName, mSharedPreferences,
|
mRetrofit, null, accountName, mSharedPreferences,
|
||||||
mPostFeedScrolledPositionSharedPreferences, null, subredditName, query, trendingSource,
|
mPostFeedScrolledPositionSharedPreferences, null, subredditName, query, trendingSource,
|
||||||
postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
|
postType, sortType, postFilter, readPosts, postEnricher)).get(PostViewModel.class);
|
||||||
} else if (postType == PostPagingSource.TYPE_SUBREDDIT) {
|
} else if (postType == PostPagingSource.TYPE_SUBREDDIT) {
|
||||||
mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(mExecutor,
|
mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(mExecutor,
|
||||||
mRetrofit, null, accountName, mSharedPreferences,
|
mRetrofit, null, accountName, mSharedPreferences,
|
||||||
mPostFeedScrolledPositionSharedPreferences, null, subredditName, postType, sortType,
|
mPostFeedScrolledPositionSharedPreferences, null, subredditName, postType, sortType,
|
||||||
postFilter, readPosts)).get(PostViewModel.class);
|
postFilter, readPosts, postEnricher)).get(PostViewModel.class);
|
||||||
} else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) {
|
} else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) {
|
||||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||||
mRetrofit, null, accountName, mSharedPreferences,
|
mRetrofit, null, accountName, mSharedPreferences,
|
||||||
mPostFeedScrolledPositionSharedPreferences, null, multiRedditPath,
|
mPostFeedScrolledPositionSharedPreferences, null, multiRedditPath,
|
||||||
postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
|
postType, sortType, postFilter, readPosts, postEnricher)).get(PostViewModel.class);
|
||||||
} else if (postType == PostPagingSource.TYPE_USER) {
|
} else if (postType == PostPagingSource.TYPE_USER) {
|
||||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||||
mRetrofit, null, accountName, mSharedPreferences,
|
mRetrofit, null, accountName, mSharedPreferences,
|
||||||
mPostFeedScrolledPositionSharedPreferences, null, username, postType, sortType, postFilter,
|
mPostFeedScrolledPositionSharedPreferences, null, username, postType, sortType, postFilter,
|
||||||
where, readPosts)).get(PostViewModel.class);
|
where, readPosts, postEnricher)).get(PostViewModel.class);
|
||||||
} else {
|
} else {
|
||||||
//Anonymous Front Page
|
//Anonymous Front Page
|
||||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||||
mRetrofit, mSharedPreferences, concatenatedSubredditNames, postType, sortType, postFilter, subredditName))
|
mRetrofit, mSharedPreferences, concatenatedSubredditNames, postType, sortType, postFilter, subredditName,
|
||||||
|
postEnricher))
|
||||||
.get(PostViewModel.class);
|
.get(PostViewModel.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1379,25 +1370,25 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_SORT_TYPE, true)) {
|
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_SORT_TYPE, true)) {
|
||||||
switch (postType) {
|
switch (postType) {
|
||||||
case PostPagingSource.TYPE_FRONT_PAGE:
|
case PostPagingSource.TYPE_FRONT_PAGE:
|
||||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, sortType.getType().name()).apply();
|
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, sortType.getType().value).apply();
|
||||||
if (sortType.getTime() != null) {
|
if (sortType.getTime() != null) {
|
||||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_BEST_POST, sortType.getTime().name()).apply();
|
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_BEST_POST, sortType.getTime().name()).apply();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PostPagingSource.TYPE_SUBREDDIT:
|
case PostPagingSource.TYPE_SUBREDDIT:
|
||||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + subredditName, sortType.getType().name()).apply();
|
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + subredditName, sortType.getType().value).apply();
|
||||||
if (sortType.getTime() != null) {
|
if (sortType.getTime() != null) {
|
||||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + subredditName, sortType.getTime().name()).apply();
|
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + subredditName, sortType.getTime().name()).apply();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PostPagingSource.TYPE_USER:
|
case PostPagingSource.TYPE_USER:
|
||||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username, sortType.getType().name()).apply();
|
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username, sortType.getType().value).apply();
|
||||||
if (sortType.getTime() != null) {
|
if (sortType.getTime() != null) {
|
||||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username, sortType.getTime().name()).apply();
|
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username, sortType.getTime().name()).apply();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PostPagingSource.TYPE_SEARCH:
|
case PostPagingSource.TYPE_SEARCH:
|
||||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, sortType.getType().name()).apply();
|
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, sortType.getType().value).apply();
|
||||||
if (sortType.getTime() != null) {
|
if (sortType.getTime() != null) {
|
||||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, sortType.getTime().name()).apply();
|
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, sortType.getTime().name()).apply();
|
||||||
}else {
|
}else {
|
||||||
@ -1407,14 +1398,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
case PostPagingSource.TYPE_MULTI_REDDIT:
|
case PostPagingSource.TYPE_MULTI_REDDIT:
|
||||||
case PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT:
|
case PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT:
|
||||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath,
|
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath,
|
||||||
sortType.getType().name()).apply();
|
sortType.getType().value).apply();
|
||||||
if (sortType.getTime() != null) {
|
if (sortType.getTime() != null) {
|
||||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath,
|
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath,
|
||||||
sortType.getTime().name()).apply();
|
sortType.getTime().name()).apply();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE:
|
case PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE:
|
||||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + "-", sortType.getType().name()).apply();
|
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + "-", sortType.getType().value).apply();
|
||||||
if (sortType.getTime() != null) {
|
if (sortType.getTime() != null) {
|
||||||
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + "-", sortType.getTime().name()).apply();
|
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + "-", sortType.getTime().name()).apply();
|
||||||
}
|
}
|
||||||
@ -2253,6 +2244,24 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SortType newSortType(String sortTypeText, String sortTimeText) {
|
||||||
|
SortType.Type st = SortType.Type.fromValue(sortTypeText);
|
||||||
|
st = st == null ? SortType.Type.NEW : st;
|
||||||
|
SortType result;
|
||||||
|
if (sortTypeText.startsWith("Top")) {
|
||||||
|
sortTimeText = st.value.substring(3);
|
||||||
|
result = new SortType(st, SortType.Time.fromValue(sortTimeText));
|
||||||
|
} else if (sortTimeText != null) {
|
||||||
|
SortType.Time sortTime = SortType.Time.fromValue(sortTimeText);
|
||||||
|
SortType.Type sortType = SortType.Type.fromValue("Top" + sortTimeText);
|
||||||
|
result = new SortType(sortType != null ? sortType : st, sortTime);
|
||||||
|
} else {
|
||||||
|
result = new SortType(st);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private static abstract class LazyModeRunnable implements Runnable {
|
private static abstract class LazyModeRunnable implements Runnable {
|
||||||
private int currentPosition = -1;
|
private int currentPosition = -1;
|
||||||
|
|
||||||
|
@ -112,6 +112,7 @@ import eu.toldi.infinityforlemmy.post.HidePost;
|
|||||||
import eu.toldi.infinityforlemmy.post.LemmyPostAPI;
|
import eu.toldi.infinityforlemmy.post.LemmyPostAPI;
|
||||||
import eu.toldi.infinityforlemmy.post.MarkPostAsRead;
|
import eu.toldi.infinityforlemmy.post.MarkPostAsRead;
|
||||||
import eu.toldi.infinityforlemmy.post.Post;
|
import eu.toldi.infinityforlemmy.post.Post;
|
||||||
|
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
|
||||||
import eu.toldi.infinityforlemmy.readpost.InsertReadPost;
|
import eu.toldi.infinityforlemmy.readpost.InsertReadPost;
|
||||||
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
|
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
|
||||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
|
||||||
@ -200,6 +201,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
MarkPostAsRead markPostAsRead;
|
MarkPostAsRead markPostAsRead;
|
||||||
@Inject
|
@Inject
|
||||||
LemmyPostAPI mLemmyPostAPI;
|
LemmyPostAPI mLemmyPostAPI;
|
||||||
|
@Inject
|
||||||
|
PostEnricher postEnricher;
|
||||||
@State
|
@State
|
||||||
Post mPost;
|
Post mPost;
|
||||||
@State
|
@State
|
||||||
@ -324,7 +327,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
mLockFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false);
|
mLockFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false);
|
||||||
mSwipeUpToHideFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_UP_TO_HIDE_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false);
|
mSwipeUpToHideFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_UP_TO_HIDE_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false);
|
||||||
mExpandChildren = !mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_TOP_LEVEL_COMMENTS_FIRST, false);
|
mExpandChildren = !mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_TOP_LEVEL_COMMENTS_FIRST, false);
|
||||||
mMarkPostsAsRead = mPostHistorySharedPreferences.getBoolean(mAccountQualifiedName + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false);
|
mMarkPostsAsRead = mPostHistorySharedPreferences.getBoolean(mAccountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false);
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
mRespectSubredditRecommendedSortType = mSharedPreferences.getBoolean(SharedPreferencesUtils.RESPECT_SUBREDDIT_RECOMMENDED_COMMENT_SORT_TYPE, false);
|
mRespectSubredditRecommendedSortType = mSharedPreferences.getBoolean(SharedPreferencesUtils.RESPECT_SUBREDDIT_RECOMMENDED_COMMENT_SORT_TYPE, false);
|
||||||
viewPostDetailFragmentId = System.currentTimeMillis();
|
viewPostDetailFragmentId = System.currentTimeMillis();
|
||||||
@ -1329,7 +1332,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
mSwipeRefreshLayout.setRefreshing(true);
|
mSwipeRefreshLayout.setRefreshing(true);
|
||||||
mGlide.clear(mFetchPostInfoImageView);
|
mGlide.clear(mFetchPostInfoImageView);
|
||||||
FetchPost.fetchPost(mExecutor, new Handler(), mRetrofit.getRetrofit(), String.valueOf(subredditId), mAccessToken,
|
FetchPost.fetchPost(mExecutor, new Handler(), mRetrofit.getRetrofit(), String.valueOf(subredditId), mAccessToken,
|
||||||
new FetchPost.FetchPostListener() {
|
postEnricher, new FetchPost.FetchPostListener() {
|
||||||
@Override
|
@Override
|
||||||
public void fetchPostSuccess(Post post) {
|
public void fetchPostSuccess(Post post) {
|
||||||
if (!isAdded()) {
|
if (!isAdded()) {
|
||||||
@ -1588,7 +1591,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
|||||||
Retrofit retrofit = mRetrofit.getRetrofit();
|
Retrofit retrofit = mRetrofit.getRetrofit();
|
||||||
|
|
||||||
FetchPost.fetchPost(mExecutor, new Handler(), retrofit, String.valueOf(mPost.getId()), mAccessToken,
|
FetchPost.fetchPost(mExecutor, new Handler(), retrofit, String.valueOf(mPost.getId()), mAccessToken,
|
||||||
new FetchPost.FetchPostListener() {
|
postEnricher, new FetchPost.FetchPostListener() {
|
||||||
@Override
|
@Override
|
||||||
public void fetchPostSuccess(Post post) {
|
public void fetchPostSuccess(Post post) {
|
||||||
if (isAdded()) {
|
if (isAdded()) {
|
||||||
|
@ -63,6 +63,7 @@ public class CreateMultiReddit {
|
|||||||
|
|
||||||
public static void anonymousCreateMultiReddit(Executor executor, Handler handler,
|
public static void anonymousCreateMultiReddit(Executor executor, Handler handler,
|
||||||
RedditDataRoomDatabase redditDataRoomDatabase,
|
RedditDataRoomDatabase redditDataRoomDatabase,
|
||||||
|
String accountName,
|
||||||
String multipath, String name, String description,
|
String multipath, String name, String description,
|
||||||
List<SubredditWithSelection> subreddits,
|
List<SubredditWithSelection> subreddits,
|
||||||
CreateMultiRedditListener createMultiRedditListener) {
|
CreateMultiRedditListener createMultiRedditListener) {
|
||||||
@ -71,7 +72,7 @@ public class CreateMultiReddit {
|
|||||||
redditDataRoomDatabase.accountDao().insert(Account.getAnonymousAccount());
|
redditDataRoomDatabase.accountDao().insert(Account.getAnonymousAccount());
|
||||||
}
|
}
|
||||||
redditDataRoomDatabase.multiRedditDao().insert(new MultiReddit(multipath, name, name, description,
|
redditDataRoomDatabase.multiRedditDao().insert(new MultiReddit(multipath, name, name, description,
|
||||||
null, null, "private", "-", 0, System.currentTimeMillis(), true, false, false));
|
null, null, "private", accountName, 0, System.currentTimeMillis(), true, false, false));
|
||||||
List<AnonymousMultiredditSubreddit> anonymousMultiredditSubreddits = new ArrayList<>();
|
List<AnonymousMultiredditSubreddit> anonymousMultiredditSubreddits = new ArrayList<>();
|
||||||
for (SubredditWithSelection s : subreddits) {
|
for (SubredditWithSelection s : subreddits) {
|
||||||
anonymousMultiredditSubreddits.add(new AnonymousMultiredditSubreddit(multipath, s.getQualifiedName()));
|
anonymousMultiredditSubreddits.add(new AnonymousMultiredditSubreddit(multipath, s.getQualifiedName()));
|
||||||
|
@ -8,6 +8,7 @@ import java.util.concurrent.Executor;
|
|||||||
|
|
||||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||||
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
||||||
|
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
import retrofit2.Response;
|
import retrofit2.Response;
|
||||||
@ -15,7 +16,7 @@ import retrofit2.Retrofit;
|
|||||||
|
|
||||||
public class FetchPost {
|
public class FetchPost {
|
||||||
public static void fetchPost(Executor executor, Handler handler, Retrofit retrofit, String id, String accessToken,
|
public static void fetchPost(Executor executor, Handler handler, Retrofit retrofit, String id, String accessToken,
|
||||||
FetchPostListener fetchPostListener) {
|
PostEnricher postEnricher, FetchPostListener fetchPostListener) {
|
||||||
Call<String> postCall;
|
Call<String> postCall;
|
||||||
// Use LemmyAPI.postInfo() instead of RedditAPI.getPost()
|
// Use LemmyAPI.postInfo() instead of RedditAPI.getPost()
|
||||||
postCall = retrofit.create(LemmyAPI.class).postInfo(Integer.parseInt(id), null, accessToken);
|
postCall = retrofit.create(LemmyAPI.class).postInfo(Integer.parseInt(id), null, accessToken);
|
||||||
@ -24,7 +25,7 @@ public class FetchPost {
|
|||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
ParsePost.parsePost(executor, handler, response.body(), new ParsePost.ParsePostListener() {
|
ParsePost.parsePost(executor, handler, postEnricher, response.body(), new ParsePost.ParsePostListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onParsePostSuccess(Post post) {
|
public void onParsePostSuccess(Post post) {
|
||||||
fetchPostListener.fetchPostSuccess(post);
|
fetchPostListener.fetchPostSuccess(post);
|
||||||
|
@ -19,6 +19,7 @@ import java.util.concurrent.Executor;
|
|||||||
|
|
||||||
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
|
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
|
||||||
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
||||||
|
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
|
||||||
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
|
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
|
||||||
import eu.toldi.infinityforlemmy.readpost.ReadPost;
|
import eu.toldi.infinityforlemmy.readpost.ReadPost;
|
||||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||||
@ -39,10 +40,11 @@ public class HistoryPostPagingSource extends ListenableFuturePagingSource<String
|
|||||||
private String username;
|
private String username;
|
||||||
private int postType;
|
private int postType;
|
||||||
private PostFilter postFilter;
|
private PostFilter postFilter;
|
||||||
|
private PostEnricher postEnricher;
|
||||||
|
|
||||||
public HistoryPostPagingSource(Retrofit retrofit, Executor executor, RedditDataRoomDatabase redditDataRoomDatabase,
|
public HistoryPostPagingSource(Retrofit retrofit, Executor executor, RedditDataRoomDatabase redditDataRoomDatabase,
|
||||||
String accessToken, String accountName, SharedPreferences sharedPreferences,
|
String accessToken, String accountName, SharedPreferences sharedPreferences,
|
||||||
String username, int postType, PostFilter postFilter) {
|
String username, int postType, PostFilter postFilter, PostEnricher postEnricher) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.redditDataRoomDatabase = redditDataRoomDatabase;
|
this.redditDataRoomDatabase = redditDataRoomDatabase;
|
||||||
@ -52,6 +54,7 @@ public class HistoryPostPagingSource extends ListenableFuturePagingSource<String
|
|||||||
this.username = username;
|
this.username = username;
|
||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
this.postFilter = postFilter;
|
this.postFilter = postFilter;
|
||||||
|
this.postEnricher = postEnricher;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -92,7 +95,7 @@ public class HistoryPostPagingSource extends ListenableFuturePagingSource<String
|
|||||||
Response<String> response = historyPosts.execute();
|
Response<String> response = historyPosts.execute();
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
String responseString = response.body();
|
String responseString = response.body();
|
||||||
LinkedHashSet<Post> newPosts = ParsePost.parsePostsSync(responseString, -1, postFilter, null);
|
LinkedHashSet<Post> newPosts = ParsePost.parsePostsSync(responseString, -1, postFilter, null, postEnricher);
|
||||||
if (newPosts == null) {
|
if (newPosts == null) {
|
||||||
return new LoadResult.Error<>(new Exception("Error parsing posts"));
|
return new LoadResult.Error<>(new Exception("Error parsing posts"));
|
||||||
} else {
|
} else {
|
||||||
|
@ -17,6 +17,7 @@ import androidx.paging.PagingLiveData;
|
|||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
|
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
|
||||||
|
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
|
||||||
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
|
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
@ -29,6 +30,7 @@ public class HistoryPostViewModel extends ViewModel {
|
|||||||
private SharedPreferences sharedPreferences;
|
private SharedPreferences sharedPreferences;
|
||||||
private int postType;
|
private int postType;
|
||||||
private PostFilter postFilter;
|
private PostFilter postFilter;
|
||||||
|
private PostEnricher postEnricher;
|
||||||
|
|
||||||
private LiveData<PagingData<Post>> posts;
|
private LiveData<PagingData<Post>> posts;
|
||||||
|
|
||||||
@ -36,7 +38,7 @@ public class HistoryPostViewModel extends ViewModel {
|
|||||||
|
|
||||||
public HistoryPostViewModel(Executor executor, Retrofit retrofit, RedditDataRoomDatabase redditDataRoomDatabase,
|
public HistoryPostViewModel(Executor executor, Retrofit retrofit, RedditDataRoomDatabase redditDataRoomDatabase,
|
||||||
String accessToken, String accountName, SharedPreferences sharedPreferences,
|
String accessToken, String accountName, SharedPreferences sharedPreferences,
|
||||||
int postType, PostFilter postFilter) {
|
int postType, PostFilter postFilter, PostEnricher postEnricher) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.redditDataRoomDatabase = redditDataRoomDatabase;
|
this.redditDataRoomDatabase = redditDataRoomDatabase;
|
||||||
@ -45,11 +47,12 @@ public class HistoryPostViewModel extends ViewModel {
|
|||||||
this.sharedPreferences = sharedPreferences;
|
this.sharedPreferences = sharedPreferences;
|
||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
this.postFilter = postFilter;
|
this.postFilter = postFilter;
|
||||||
|
this.postEnricher = postEnricher;
|
||||||
|
|
||||||
postFilterLiveData = new MutableLiveData<>();
|
postFilterLiveData = new MutableLiveData<>();
|
||||||
postFilterLiveData.postValue(postFilter);
|
postFilterLiveData.postValue(postFilter);
|
||||||
|
|
||||||
Pager<String, Post> pager = new Pager<>(new PagingConfig(25, 25, false), this::returnPagingSoruce);
|
Pager<String, Post> pager = new Pager<>(new PagingConfig(25, 25, false), this::returnPagingSource);
|
||||||
|
|
||||||
posts = Transformations.switchMap(postFilterLiveData, postFilterValue -> PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this)));
|
posts = Transformations.switchMap(postFilterLiveData, postFilterValue -> PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this)));
|
||||||
}
|
}
|
||||||
@ -58,19 +61,9 @@ public class HistoryPostViewModel extends ViewModel {
|
|||||||
return posts;
|
return posts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HistoryPostPagingSource returnPagingSoruce() {
|
public HistoryPostPagingSource returnPagingSource() {
|
||||||
HistoryPostPagingSource paging3PagingSource;
|
return new HistoryPostPagingSource(retrofit, executor, redditDataRoomDatabase, accessToken, accountName,
|
||||||
switch (postType) {
|
sharedPreferences, accountName, postType, postFilter, postEnricher);
|
||||||
case HistoryPostPagingSource.TYPE_READ_POSTS:
|
|
||||||
paging3PagingSource = new HistoryPostPagingSource(retrofit, executor, redditDataRoomDatabase, accessToken, accountName,
|
|
||||||
sharedPreferences, accountName, postType, postFilter);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
paging3PagingSource = new HistoryPostPagingSource(retrofit, executor, redditDataRoomDatabase, accessToken, accountName,
|
|
||||||
sharedPreferences, accountName, postType, postFilter);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return paging3PagingSource;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changePostFilter(PostFilter postFilter) {
|
public void changePostFilter(PostFilter postFilter) {
|
||||||
@ -86,10 +79,11 @@ public class HistoryPostViewModel extends ViewModel {
|
|||||||
private SharedPreferences sharedPreferences;
|
private SharedPreferences sharedPreferences;
|
||||||
private int postType;
|
private int postType;
|
||||||
private PostFilter postFilter;
|
private PostFilter postFilter;
|
||||||
|
private PostEnricher postEnricher;
|
||||||
|
|
||||||
public Factory(Executor executor, Retrofit retrofit, RedditDataRoomDatabase redditDataRoomDatabase,
|
public Factory(Executor executor, Retrofit retrofit, RedditDataRoomDatabase redditDataRoomDatabase,
|
||||||
String accessToken, String accountName, SharedPreferences sharedPreferences, int postType,
|
String accessToken, String accountName, SharedPreferences sharedPreferences, int postType,
|
||||||
PostFilter postFilter) {
|
PostFilter postFilter, PostEnricher postEnricher) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.redditDataRoomDatabase = redditDataRoomDatabase;
|
this.redditDataRoomDatabase = redditDataRoomDatabase;
|
||||||
@ -98,18 +92,14 @@ public class HistoryPostViewModel extends ViewModel {
|
|||||||
this.sharedPreferences = sharedPreferences;
|
this.sharedPreferences = sharedPreferences;
|
||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
this.postFilter = postFilter;
|
this.postFilter = postFilter;
|
||||||
|
this.postEnricher = postEnricher;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
||||||
if (postType == HistoryPostPagingSource.TYPE_READ_POSTS) {
|
return (T) new HistoryPostViewModel(executor, retrofit, redditDataRoomDatabase, accessToken, accountName, sharedPreferences,
|
||||||
return (T) new HistoryPostViewModel(executor, retrofit, redditDataRoomDatabase, accessToken, accountName, sharedPreferences,
|
postType, postFilter, postEnricher);
|
||||||
postType, postFilter);
|
|
||||||
} else {
|
|
||||||
return (T) new HistoryPostViewModel(executor, retrofit, redditDataRoomDatabase, accessToken, accountName, sharedPreferences,
|
|
||||||
postType, postFilter);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import eu.toldi.infinityforlemmy.community.BasicCommunityInfo;
|
import eu.toldi.infinityforlemmy.community.BasicCommunityInfo;
|
||||||
|
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
|
||||||
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
|
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
|
||||||
import eu.toldi.infinityforlemmy.user.BasicUserInfo;
|
import eu.toldi.infinityforlemmy.user.BasicUserInfo;
|
||||||
import eu.toldi.infinityforlemmy.utils.JSONUtils;
|
import eu.toldi.infinityforlemmy.utils.JSONUtils;
|
||||||
@ -45,7 +46,8 @@ import eu.toldi.infinityforlemmy.utils.Utils;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public class ParsePost {
|
public class ParsePost {
|
||||||
public static LinkedHashSet<Post> parsePostsSync(String response, int nPosts, PostFilter postFilter, List<String> readPostList) {
|
public static LinkedHashSet<Post> parsePostsSync(String response, int nPosts, PostFilter postFilter,
|
||||||
|
List<String> readPostList, PostEnricher postEnricher) {
|
||||||
LinkedHashSet<Post> newPosts = new LinkedHashSet<>();
|
LinkedHashSet<Post> newPosts = new LinkedHashSet<>();
|
||||||
try {
|
try {
|
||||||
JSONObject jsonResponse = new JSONObject(response);
|
JSONObject jsonResponse = new JSONObject(response);
|
||||||
@ -80,6 +82,8 @@ public class ParsePost {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
postEnricher.enrich(newPosts);
|
||||||
|
|
||||||
return newPosts;
|
return newPosts;
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -87,21 +91,9 @@ public class ParsePost {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getLastItem(String response) {
|
|
||||||
try {
|
|
||||||
JSONObject object = new JSONObject(response).getJSONObject(JSONUtils.DATA_KEY);
|
|
||||||
return object.isNull(JSONUtils.AFTER_KEY) ? null : object.getString(JSONUtils.AFTER_KEY);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void parsePost(Executor executor, Handler handler, String response, ParsePostListener parsePostListener) {
|
|
||||||
PostFilter postFilter = new PostFilter();
|
|
||||||
postFilter.allowNSFW = true;
|
|
||||||
|
|
||||||
|
public static void parsePost(Executor executor, Handler handler, PostEnricher postEnricher,
|
||||||
|
String response, ParsePostListener parsePostListener) {
|
||||||
executor.execute(() -> {
|
executor.execute(() -> {
|
||||||
try {
|
try {
|
||||||
JSONObject allData = new JSONObject(response).getJSONObject("post_view");
|
JSONObject allData = new JSONObject(response).getJSONObject("post_view");
|
||||||
@ -111,6 +103,7 @@ public class ParsePost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Post post = parseBasicData(allData);
|
Post post = parseBasicData(allData);
|
||||||
|
postEnricher.enrich(List.of(post));
|
||||||
handler.post(() -> parsePostListener.onParsePostSuccess(post));
|
handler.post(() -> parsePostListener.onParsePostSuccess(post));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -188,7 +181,7 @@ public class ParsePost {
|
|||||||
boolean nsfw = post.getBoolean("nsfw");
|
boolean nsfw = post.getBoolean("nsfw");
|
||||||
boolean locked = post.getBoolean("locked");
|
boolean locked = post.getBoolean("locked");
|
||||||
boolean saved = data.getBoolean("saved");
|
boolean saved = data.getBoolean("saved");
|
||||||
String distinguished = (creator.getBoolean("admin") ? "admin" : "");
|
String distinguished = creator.optBoolean("admin") ? "admin" : "";
|
||||||
String suggestedSort = "";
|
String suggestedSort = "";
|
||||||
ArrayList<Post.Preview> previews = new ArrayList<>();
|
ArrayList<Post.Preview> previews = new ArrayList<>();
|
||||||
if (!post.isNull("thumbnail_url")) {
|
if (!post.isNull("thumbnail_url")) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package eu.toldi.infinityforlemmy.post;
|
package eu.toldi.infinityforlemmy.post;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Build;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.paging.ListenableFuturePagingSource;
|
import androidx.paging.ListenableFuturePagingSource;
|
||||||
@ -13,6 +14,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -22,6 +24,7 @@ import java.util.regex.Pattern;
|
|||||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||||
import eu.toldi.infinityforlemmy.SortType;
|
import eu.toldi.infinityforlemmy.SortType;
|
||||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||||
|
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
|
||||||
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
|
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
|
||||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||||
import retrofit2.HttpException;
|
import retrofit2.HttpException;
|
||||||
@ -58,6 +61,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
private List<String> readPostList;
|
private List<String> readPostList;
|
||||||
private String userWhere;
|
private String userWhere;
|
||||||
private String multiRedditPath;
|
private String multiRedditPath;
|
||||||
|
private final PostEnricher postEnricher;
|
||||||
private LinkedHashSet<Post> postLinkedHashSet;
|
private LinkedHashSet<Post> postLinkedHashSet;
|
||||||
|
|
||||||
private int page = 1;
|
private int page = 1;
|
||||||
@ -65,7 +69,8 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
PostPagingSource(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
PostPagingSource(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
||||||
SharedPreferences sharedPreferences,
|
SharedPreferences sharedPreferences,
|
||||||
SharedPreferences postFeedScrolledPositionSharedPreferences, int postType,
|
SharedPreferences postFeedScrolledPositionSharedPreferences, int postType,
|
||||||
SortType sortType, PostFilter postFilter, List<String> readPostList, String option) {
|
SortType sortType, PostFilter postFilter, List<String> readPostList, String option,
|
||||||
|
PostEnricher postEnricher) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
@ -77,13 +82,14 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
this.sortType = sortType == null ? new SortType(SortType.Type.ACTIVE) : sortType;
|
this.sortType = sortType == null ? new SortType(SortType.Type.ACTIVE) : sortType;
|
||||||
this.postFilter = postFilter;
|
this.postFilter = postFilter;
|
||||||
this.readPostList = readPostList;
|
this.readPostList = readPostList;
|
||||||
|
this.postEnricher = postEnricher;
|
||||||
postLinkedHashSet = new LinkedHashSet<>();
|
postLinkedHashSet = new LinkedHashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
PostPagingSource(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
PostPagingSource(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
||||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||||
String path, int postType, SortType sortType, PostFilter postFilter,
|
String path, int postType, SortType sortType, PostFilter postFilter,
|
||||||
List<String> readPostList) {
|
List<String> readPostList, PostEnricher postEnricher) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
@ -93,15 +99,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
if (postType == TYPE_SUBREDDIT || postType == TYPE_ANONYMOUS_FRONT_PAGE) {
|
if (postType == TYPE_SUBREDDIT || postType == TYPE_ANONYMOUS_FRONT_PAGE) {
|
||||||
this.subredditOrUserName = path;
|
this.subredditOrUserName = path;
|
||||||
} else {
|
} else {
|
||||||
if (sortType != null) {
|
multiRedditPath = path;
|
||||||
if (path.endsWith("/")) {
|
|
||||||
multiRedditPath = path + sortType.getType().value;
|
|
||||||
} else {
|
|
||||||
multiRedditPath = path + "/" + sortType.getType().value;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
multiRedditPath = path;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
if (sortType == null) {
|
if (sortType == null) {
|
||||||
@ -115,13 +113,14 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
}
|
}
|
||||||
this.postFilter = postFilter;
|
this.postFilter = postFilter;
|
||||||
this.readPostList = readPostList;
|
this.readPostList = readPostList;
|
||||||
|
this.postEnricher = postEnricher;
|
||||||
postLinkedHashSet = new LinkedHashSet<>();
|
postLinkedHashSet = new LinkedHashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
PostPagingSource(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
PostPagingSource(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
||||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||||
String subredditOrUserName, int postType, SortType sortType, PostFilter postFilter,
|
String subredditOrUserName, int postType, SortType sortType, PostFilter postFilter,
|
||||||
String where, List<String> readPostList) {
|
String where, List<String> readPostList, PostEnricher postEnricher) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
@ -134,13 +133,14 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
this.postFilter = postFilter;
|
this.postFilter = postFilter;
|
||||||
userWhere = where;
|
userWhere = where;
|
||||||
this.readPostList = readPostList;
|
this.readPostList = readPostList;
|
||||||
|
this.postEnricher = postEnricher;
|
||||||
postLinkedHashSet = new LinkedHashSet<>();
|
postLinkedHashSet = new LinkedHashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
PostPagingSource(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
PostPagingSource(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
||||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||||
String subredditOrUserName, String query, String trendingSource, int postType,
|
String subredditOrUserName, String query, String trendingSource, int postType,
|
||||||
SortType sortType, PostFilter postFilter, List<String> readPostList) {
|
SortType sortType, PostFilter postFilter, List<String> readPostList, PostEnricher postEnricher) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
@ -153,8 +153,9 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
this.sortType = sortType == null ? new SortType(SortType.Type.TOP) : sortType;
|
this.sortType = sortType == null ? new SortType(SortType.Type.TOP) : sortType;
|
||||||
this.postFilter = postFilter;
|
this.postFilter = postFilter;
|
||||||
postLinkedHashSet = new LinkedHashSet<>();
|
|
||||||
this.readPostList = readPostList;
|
this.readPostList = readPostList;
|
||||||
|
this.postEnricher = postEnricher;
|
||||||
|
postLinkedHashSet = new LinkedHashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -177,21 +178,18 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
return loadSearchPosts(loadParams, api);
|
return loadSearchPosts(loadParams, api);
|
||||||
case TYPE_SUBREDDIT:
|
case TYPE_SUBREDDIT:
|
||||||
return loadSubredditPosts(loadParams, api);
|
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:
|
case TYPE_MULTI_REDDIT:
|
||||||
return loadMultipleSubredditPosts(loadParams, api, List.of(multiRedditPath.split(Pattern.quote("+"))));
|
return loadMultipleSubredditPosts(loadParams, api, List.of(multiRedditPath.split(Pattern.quote(","))));
|
||||||
/* default:
|
case TYPE_ANONYMOUS_FRONT_PAGE:
|
||||||
return loadAnonymousHomePosts(loadParams, api);*/
|
default:
|
||||||
|
return loadAnonymousHomePosts(loadParams, api);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public LoadResult<Integer, Post> transformData(Response<String> response) {
|
public LoadResult<Integer, Post> transformData(Response<String> response) {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
String responseString = response.body();
|
String responseString = response.body();
|
||||||
LinkedHashSet<Post> newPosts = ParsePost.parsePostsSync(responseString, -1, postFilter, readPostList);
|
LinkedHashSet<Post> newPosts = ParsePost.parsePostsSync(responseString, -1, postFilter, readPostList, postEnricher);
|
||||||
|
|
||||||
if (newPosts == null) {
|
if (newPosts == null) {
|
||||||
return new LoadResult.Error<>(new Exception("Error parsing posts"));
|
return new LoadResult.Error<>(new Exception("Error parsing posts"));
|
||||||
@ -237,7 +235,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
}
|
}
|
||||||
String feed_type = Objects.equals(subredditOrUserName, "all") ? "All" : Objects.equals(subredditOrUserName, "local") ? "Local" : "Subscribed";
|
String feed_type = Objects.equals(subredditOrUserName, "all") ? "All" : Objects.equals(subredditOrUserName, "local") ? "Local" : "Subscribed";
|
||||||
|
|
||||||
bestPost = api.getPosts(feed_type,sortType.getType().value,page,25,null,null,false,accessToken);
|
bestPost = api.getPostsListenableFuture(feed_type, sortType.getType().value, page, 25, null, null, false, accessToken);
|
||||||
|
|
||||||
ListenableFuture<LoadResult<Integer, Post>> pageFuture = Futures.transform(bestPost, this::transformData, executor);
|
ListenableFuture<LoadResult<Integer, Post>> pageFuture = Futures.transform(bestPost, this::transformData, executor);
|
||||||
|
|
||||||
@ -252,7 +250,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
private ListenableFuture<LoadResult<Integer, Post>> loadSubredditPosts(@NonNull LoadParams<Integer> loadParams, LemmyAPI api) {
|
private ListenableFuture<LoadResult<Integer, Post>> loadSubredditPosts(@NonNull LoadParams<Integer> loadParams, LemmyAPI api) {
|
||||||
ListenableFuture<Response<String>> subredditPost;
|
ListenableFuture<Response<String>> subredditPost;
|
||||||
|
|
||||||
subredditPost = api.getPosts(null,sortType.getType().value,loadParams.getKey(),25,null,subredditOrUserName,false,accessToken);
|
subredditPost = api.getPostsListenableFuture(null, sortType.getType().value, loadParams.getKey(), 25, null, subredditOrUserName, false, accessToken);
|
||||||
|
|
||||||
|
|
||||||
ListenableFuture<LoadResult<Integer, Post>> pageFuture = Futures.transform(subredditPost, this::transformData, executor);
|
ListenableFuture<LoadResult<Integer, Post>> pageFuture = Futures.transform(subredditPost, this::transformData, executor);
|
||||||
@ -267,7 +265,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
|
|
||||||
private ListenableFuture<LoadResult<Integer, Post>> loadUserPosts(@NonNull LoadParams<Integer> loadParams, LemmyAPI api) {
|
private ListenableFuture<LoadResult<Integer, Post>> loadUserPosts(@NonNull LoadParams<Integer> loadParams, LemmyAPI api) {
|
||||||
ListenableFuture<Response<String>> userPosts;
|
ListenableFuture<Response<String>> userPosts;
|
||||||
userPosts = api.getUserPosts(subredditOrUserName, sortType.getType().value, loadParams.getKey(), 25, userWhere.equals(USER_WHERE_SAVED), accessToken);
|
userPosts = api.getUserPostsListenableFuture(subredditOrUserName, sortType.getType().value, loadParams.getKey(), 25, userWhere.equals(USER_WHERE_SAVED), accessToken);
|
||||||
|
|
||||||
|
|
||||||
ListenableFuture<LoadResult<Integer, Post>> pageFuture = Futures.transform(userPosts, this::transformData, executor);
|
ListenableFuture<LoadResult<Integer, Post>> pageFuture = Futures.transform(userPosts, this::transformData, executor);
|
||||||
@ -302,7 +300,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
for (String community : communities) {
|
for (String community : communities) {
|
||||||
ListenableFuture<Response<String>> subredditPost;
|
ListenableFuture<Response<String>> subredditPost;
|
||||||
|
|
||||||
subredditPost = api.getPosts(null, sortType.getType().value, loadParams.getKey(), 25, null, community, false, accessToken);
|
subredditPost = api.getPostsListenableFuture(null, sortType.getType().value, loadParams.getKey(), 25, null, community, false, accessToken);
|
||||||
|
|
||||||
ListenableFuture<LoadResult<Integer, Post>> communityFuture = Futures.transform(subredditPost,
|
ListenableFuture<LoadResult<Integer, Post>> communityFuture = Futures.transform(subredditPost,
|
||||||
this::transformData, executor);
|
this::transformData, executor);
|
||||||
@ -326,6 +324,12 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sortType.getType().equals(SortType.Type.NEW)) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
|
combinedPosts.sort((o1, o2) -> Long.compare(o2.getPostTimeMillis(), o1.getPostTimeMillis()));
|
||||||
|
}
|
||||||
|
}
|
||||||
return new LoadResult.Page<>(combinedPosts, null, null);
|
return new LoadResult.Page<>(combinedPosts, null, null);
|
||||||
}, executor);
|
}, executor);
|
||||||
}
|
}
|
||||||
@ -343,20 +347,6 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
|
|
||||||
ListenableFuture<LoadResult<String, Post>> pageFuture = Futures.transform(multiRedditPosts, this::transformData, executor);
|
ListenableFuture<LoadResult<String, Post>> pageFuture = Futures.transform(multiRedditPosts, this::transformData, executor);
|
||||||
|
|
||||||
ListenableFuture<LoadResult<String, Post>> partialLoadResultFuture =
|
|
||||||
Futures.catching(pageFuture, HttpException.class,
|
|
||||||
LoadResult.Error::new, executor);
|
|
||||||
|
|
||||||
return Futures.catching(partialLoadResultFuture,
|
|
||||||
IOException.class, LoadResult.Error::new, executor);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ListenableFuture<LoadResult<String, Post>> loadAnonymousHomePosts(@NonNull LoadParams<String> loadParams, LemmyAPI api) {
|
|
||||||
ListenableFuture<Response<String>> anonymousHomePosts;
|
|
||||||
anonymousHomePosts = api.getSubredditBestPostsListenableFuture(subredditOrUserName, sortType.getType(), sortType.getTime(), loadParams.getKey());
|
|
||||||
|
|
||||||
ListenableFuture<LoadResult<String, Post>> pageFuture = Futures.transform(anonymousHomePosts, this::transformData, executor);
|
|
||||||
|
|
||||||
ListenableFuture<LoadResult<String, Post>> partialLoadResultFuture =
|
ListenableFuture<LoadResult<String, Post>> partialLoadResultFuture =
|
||||||
Futures.catching(pageFuture, HttpException.class,
|
Futures.catching(pageFuture, HttpException.class,
|
||||||
LoadResult.Error::new, executor);
|
LoadResult.Error::new, executor);
|
||||||
@ -365,6 +355,14 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
IOException.class, LoadResult.Error::new, executor);
|
IOException.class, LoadResult.Error::new, executor);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
private ListenableFuture<LoadResult<Integer, Post>> loadAnonymousHomePosts(@NonNull LoadParams<Integer> loadParams, LemmyAPI api) {
|
||||||
|
if (subredditOrUserName == null) {
|
||||||
|
// Return empty list
|
||||||
|
return Futures.immediateFuture(new LoadResult.Page<>(new ArrayList<>(), null, null));
|
||||||
|
}
|
||||||
|
return loadMultipleSubredditPosts(loadParams, api, Arrays.asList(subredditOrUserName.split(Pattern.quote(","))));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getKeyReuseSupported() {
|
public boolean getKeyReuseSupported() {
|
||||||
//TODO: Figure out why this is needed
|
//TODO: Figure out why this is needed
|
||||||
|
@ -23,6 +23,7 @@ import java.util.concurrent.Executor;
|
|||||||
|
|
||||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||||
import eu.toldi.infinityforlemmy.SortType;
|
import eu.toldi.infinityforlemmy.SortType;
|
||||||
|
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
|
||||||
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
|
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
|
||||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||||
|
|
||||||
@ -41,6 +42,7 @@ public class PostViewModel extends ViewModel {
|
|||||||
private PostFilter postFilter;
|
private PostFilter postFilter;
|
||||||
private String userWhere;
|
private String userWhere;
|
||||||
private List<String> readPostList;
|
private List<String> readPostList;
|
||||||
|
private PostEnricher postEnricher;
|
||||||
private MutableLiveData<Boolean> currentlyReadPostIdsLiveData = new MutableLiveData<>();
|
private MutableLiveData<Boolean> currentlyReadPostIdsLiveData = new MutableLiveData<>();
|
||||||
|
|
||||||
private LiveData<PagingData<Post>> posts;
|
private LiveData<PagingData<Post>> posts;
|
||||||
@ -53,7 +55,7 @@ public class PostViewModel extends ViewModel {
|
|||||||
public PostViewModel(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
public PostViewModel(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
||||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||||
@Nullable SharedPreferences postHistorySharedPreferences, int postType,
|
@Nullable SharedPreferences postHistorySharedPreferences, int postType,
|
||||||
SortType sortType, PostFilter postFilter, List<String> readPostList, String option) {
|
SortType sortType, PostFilter postFilter, List<String> readPostList, String option, PostEnricher postEnricher) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
@ -65,6 +67,7 @@ public class PostViewModel extends ViewModel {
|
|||||||
this.postFilter = postFilter;
|
this.postFilter = postFilter;
|
||||||
this.readPostList = readPostList;
|
this.readPostList = readPostList;
|
||||||
this.name = option;
|
this.name = option;
|
||||||
|
this.postEnricher = postEnricher;
|
||||||
|
|
||||||
sortTypeLiveData = new MutableLiveData<>();
|
sortTypeLiveData = new MutableLiveData<>();
|
||||||
sortTypeLiveData.postValue(sortType);
|
sortTypeLiveData.postValue(sortType);
|
||||||
@ -95,7 +98,7 @@ public class PostViewModel extends ViewModel {
|
|||||||
public PostViewModel(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
public PostViewModel(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
||||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||||
@Nullable SharedPreferences postHistorySharedPreferences, String subredditName, int postType,
|
@Nullable SharedPreferences postHistorySharedPreferences, String subredditName, int postType,
|
||||||
SortType sortType, PostFilter postFilter, List<String> readPostList) {
|
SortType sortType, PostFilter postFilter, List<String> readPostList, PostEnricher postEnricher) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
@ -107,6 +110,7 @@ public class PostViewModel extends ViewModel {
|
|||||||
this.postFilter = postFilter;
|
this.postFilter = postFilter;
|
||||||
this.readPostList = readPostList;
|
this.readPostList = readPostList;
|
||||||
this.name = subredditName;
|
this.name = subredditName;
|
||||||
|
this.postEnricher = postEnricher;
|
||||||
|
|
||||||
sortTypeLiveData = new MutableLiveData<>();
|
sortTypeLiveData = new MutableLiveData<>();
|
||||||
sortTypeLiveData.postValue(sortType);
|
sortTypeLiveData.postValue(sortType);
|
||||||
@ -139,7 +143,7 @@ public class PostViewModel extends ViewModel {
|
|||||||
SharedPreferences postFeedScrolledPositionSharedPreferences,
|
SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||||
@Nullable SharedPreferences postHistorySharedPreferences, String username,
|
@Nullable SharedPreferences postHistorySharedPreferences, String username,
|
||||||
int postType, SortType sortType, PostFilter postFilter, String userWhere,
|
int postType, SortType sortType, PostFilter postFilter, String userWhere,
|
||||||
List<String> readPostList) {
|
List<String> readPostList, PostEnricher postEnricher) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
@ -152,6 +156,7 @@ public class PostViewModel extends ViewModel {
|
|||||||
this.readPostList = readPostList;
|
this.readPostList = readPostList;
|
||||||
this.name = username;
|
this.name = username;
|
||||||
this.userWhere = userWhere;
|
this.userWhere = userWhere;
|
||||||
|
this.postEnricher = postEnricher;
|
||||||
|
|
||||||
sortTypeLiveData = new MutableLiveData<>();
|
sortTypeLiveData = new MutableLiveData<>();
|
||||||
sortTypeLiveData.postValue(sortType);
|
sortTypeLiveData.postValue(sortType);
|
||||||
@ -183,7 +188,7 @@ public class PostViewModel extends ViewModel {
|
|||||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||||
@Nullable SharedPreferences postHistorySharedPreferences, String subredditName, String query,
|
@Nullable SharedPreferences postHistorySharedPreferences, String subredditName, String query,
|
||||||
String trendingSource, int postType, SortType sortType, PostFilter postFilter,
|
String trendingSource, int postType, SortType sortType, PostFilter postFilter,
|
||||||
List<String> readPostList) {
|
List<String> readPostList, PostEnricher postEnricher) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
@ -197,6 +202,7 @@ public class PostViewModel extends ViewModel {
|
|||||||
this.name = subredditName;
|
this.name = subredditName;
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.trendingSource = trendingSource;
|
this.trendingSource = trendingSource;
|
||||||
|
this.postEnricher = postEnricher;
|
||||||
|
|
||||||
sortTypeLiveData = new MutableLiveData<>();
|
sortTypeLiveData = new MutableLiveData<>();
|
||||||
sortTypeLiveData.postValue(sortType);
|
sortTypeLiveData.postValue(sortType);
|
||||||
@ -238,25 +244,25 @@ public class PostViewModel extends ViewModel {
|
|||||||
case PostPagingSource.TYPE_FRONT_PAGE:
|
case PostPagingSource.TYPE_FRONT_PAGE:
|
||||||
paging3PagingSource = new PostPagingSource(executor, retrofit, accessToken, accountName,
|
paging3PagingSource = new PostPagingSource(executor, retrofit, accessToken, accountName,
|
||||||
sharedPreferences, postFeedScrolledPositionSharedPreferences, postType, sortType,
|
sharedPreferences, postFeedScrolledPositionSharedPreferences, postType, sortType,
|
||||||
postFilter, readPostList,name);
|
postFilter, readPostList, name, postEnricher);
|
||||||
break;
|
break;
|
||||||
case PostPagingSource.TYPE_SUBREDDIT:
|
case PostPagingSource.TYPE_SUBREDDIT:
|
||||||
case PostPagingSource.TYPE_MULTI_REDDIT:
|
case PostPagingSource.TYPE_MULTI_REDDIT:
|
||||||
case PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE:
|
case PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE:
|
||||||
paging3PagingSource = new PostPagingSource(executor, retrofit, accessToken, accountName,
|
paging3PagingSource = new PostPagingSource(executor, retrofit, accessToken, accountName,
|
||||||
sharedPreferences, postFeedScrolledPositionSharedPreferences, name, postType,
|
sharedPreferences, postFeedScrolledPositionSharedPreferences, name, postType,
|
||||||
sortType, postFilter, readPostList);
|
sortType, postFilter, readPostList, postEnricher);
|
||||||
break;
|
break;
|
||||||
case PostPagingSource.TYPE_SEARCH:
|
case PostPagingSource.TYPE_SEARCH:
|
||||||
paging3PagingSource = new PostPagingSource(executor, retrofit, accessToken, accountName,
|
paging3PagingSource = new PostPagingSource(executor, retrofit, accessToken, accountName,
|
||||||
sharedPreferences, postFeedScrolledPositionSharedPreferences, name, query, trendingSource,
|
sharedPreferences, postFeedScrolledPositionSharedPreferences, name, query, trendingSource,
|
||||||
postType, sortType, postFilter, readPostList);
|
postType, sortType, postFilter, readPostList, postEnricher);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
//User
|
//User
|
||||||
paging3PagingSource = new PostPagingSource(executor, retrofit, accessToken, accountName,
|
paging3PagingSource = new PostPagingSource(executor, retrofit, accessToken, accountName,
|
||||||
sharedPreferences, postFeedScrolledPositionSharedPreferences, name, postType,
|
sharedPreferences, postFeedScrolledPositionSharedPreferences, name, postType,
|
||||||
sortType, postFilter, userWhere, readPostList);
|
sortType, postFilter, userWhere, readPostList, postEnricher);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return paging3PagingSource;
|
return paging3PagingSource;
|
||||||
@ -291,11 +297,12 @@ public class PostViewModel extends ViewModel {
|
|||||||
private PostFilter postFilter;
|
private PostFilter postFilter;
|
||||||
private String userWhere;
|
private String userWhere;
|
||||||
private List<String> readPostList;
|
private List<String> readPostList;
|
||||||
|
private PostEnricher postEnricher;
|
||||||
|
|
||||||
public Factory(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
public Factory(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
||||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||||
SharedPreferences postHistorySharedPreferences, int postType, SortType sortType,
|
SharedPreferences postHistorySharedPreferences, int postType, SortType sortType,
|
||||||
PostFilter postFilter, List<String> readPostList, String option) {
|
PostFilter postFilter, List<String> readPostList, String option, PostEnricher postEnricher) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
@ -308,12 +315,13 @@ public class PostViewModel extends ViewModel {
|
|||||||
this.postFilter = postFilter;
|
this.postFilter = postFilter;
|
||||||
this.readPostList = readPostList;
|
this.readPostList = readPostList;
|
||||||
this.name = option;
|
this.name = option;
|
||||||
|
this.postEnricher = postEnricher;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Factory(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
public Factory(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
||||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||||
SharedPreferences postHistorySharedPreferences, String name, int postType, SortType sortType,
|
SharedPreferences postHistorySharedPreferences, String name, int postType, SortType sortType,
|
||||||
PostFilter postFilter, List<String> readPostList) {
|
PostFilter postFilter, List<String> readPostList, PostEnricher postEnricher) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
@ -326,13 +334,15 @@ public class PostViewModel extends ViewModel {
|
|||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
this.postFilter = postFilter;
|
this.postFilter = postFilter;
|
||||||
this.readPostList = readPostList;
|
this.readPostList = readPostList;
|
||||||
|
this.postEnricher = postEnricher;
|
||||||
}
|
}
|
||||||
|
|
||||||
//User posts
|
//User posts
|
||||||
public Factory(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
public Factory(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
||||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||||
SharedPreferences postHistorySharedPreferences, String username, int postType,
|
SharedPreferences postHistorySharedPreferences, String username, int postType,
|
||||||
SortType sortType, PostFilter postFilter, String where, List<String> readPostList) {
|
SortType sortType, PostFilter postFilter, String where, List<String> readPostList,
|
||||||
|
PostEnricher postEnricher) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
@ -346,12 +356,14 @@ public class PostViewModel extends ViewModel {
|
|||||||
this.postFilter = postFilter;
|
this.postFilter = postFilter;
|
||||||
userWhere = where;
|
userWhere = where;
|
||||||
this.readPostList = readPostList;
|
this.readPostList = readPostList;
|
||||||
|
this.postEnricher = postEnricher;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Factory(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
public Factory(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
|
||||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||||
SharedPreferences postHistorySharedPreferences, String name, String query, String trendingSource,
|
SharedPreferences postHistorySharedPreferences, String name, String query, String trendingSource,
|
||||||
int postType, SortType sortType, PostFilter postFilter, List<String> readPostList) {
|
int postType, SortType sortType, PostFilter postFilter, List<String> readPostList,
|
||||||
|
PostEnricher postEnricher) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
@ -366,19 +378,23 @@ public class PostViewModel extends ViewModel {
|
|||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
this.postFilter = postFilter;
|
this.postFilter = postFilter;
|
||||||
this.readPostList = readPostList;
|
this.readPostList = readPostList;
|
||||||
|
this.postEnricher = postEnricher;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Anonymous Front Page
|
//Anonymous Front Page
|
||||||
public Factory(Executor executor, RetrofitHolder retrofit, SharedPreferences sharedPreferences,
|
public Factory(Executor executor, RetrofitHolder retrofit, SharedPreferences sharedPreferences,
|
||||||
String concatenatedSubredditNames, int postType, SortType sortType, PostFilter postFilter, String opt) {
|
String concatenatedSubredditNames, int postType, SortType sortType, PostFilter postFilter,
|
||||||
|
String opt, PostEnricher postEnricher) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.sharedPreferences = sharedPreferences;
|
this.sharedPreferences = sharedPreferences;
|
||||||
|
// TODO is this used? because it is getting overwritten with opt
|
||||||
this.name = concatenatedSubredditNames;
|
this.name = concatenatedSubredditNames;
|
||||||
this.postType = postType;
|
this.postType = postType;
|
||||||
this.sortType = sortType;
|
this.sortType = sortType;
|
||||||
this.postFilter = postFilter;
|
this.postFilter = postFilter;
|
||||||
this.name = opt;
|
this.name = opt;
|
||||||
|
this.postEnricher = postEnricher;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -387,23 +403,23 @@ public class PostViewModel extends ViewModel {
|
|||||||
if (postType == PostPagingSource.TYPE_FRONT_PAGE) {
|
if (postType == PostPagingSource.TYPE_FRONT_PAGE) {
|
||||||
return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
|
return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
|
||||||
postFeedScrolledPositionSharedPreferences, postHistorySharedPreferences, postType,
|
postFeedScrolledPositionSharedPreferences, postHistorySharedPreferences, postType,
|
||||||
sortType, postFilter, readPostList,name);
|
sortType, postFilter, readPostList,name, postEnricher);
|
||||||
} else if (postType == PostPagingSource.TYPE_SEARCH) {
|
} else if (postType == PostPagingSource.TYPE_SEARCH) {
|
||||||
return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
|
return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
|
||||||
postFeedScrolledPositionSharedPreferences, postHistorySharedPreferences, name, query,
|
postFeedScrolledPositionSharedPreferences, postHistorySharedPreferences, name, query,
|
||||||
trendingSource, postType, sortType, postFilter, readPostList);
|
trendingSource, postType, sortType, postFilter, readPostList, postEnricher);
|
||||||
} else if (postType == PostPagingSource.TYPE_SUBREDDIT || postType == PostPagingSource.TYPE_MULTI_REDDIT) {
|
} else if (postType == PostPagingSource.TYPE_SUBREDDIT || postType == PostPagingSource.TYPE_MULTI_REDDIT) {
|
||||||
return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
|
return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
|
||||||
postFeedScrolledPositionSharedPreferences, postHistorySharedPreferences, name,
|
postFeedScrolledPositionSharedPreferences, postHistorySharedPreferences, name,
|
||||||
postType, sortType, postFilter, readPostList);
|
postType, sortType, postFilter, readPostList, postEnricher);
|
||||||
} else if (postType == PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE) {
|
} else if (postType == PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE) {
|
||||||
return (T) new PostViewModel(executor, retrofit, null, null, sharedPreferences,
|
return (T) new PostViewModel(executor, retrofit, null, null, sharedPreferences,
|
||||||
null, null, name, postType, sortType,
|
null, null, name, postType, sortType,
|
||||||
postFilter, null);
|
postFilter, null, postEnricher);
|
||||||
} else {
|
} else {
|
||||||
return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
|
return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
|
||||||
postFeedScrolledPositionSharedPreferences, postHistorySharedPreferences, name,
|
postFeedScrolledPositionSharedPreferences, postHistorySharedPreferences, name,
|
||||||
postType, sortType, postFilter, userWhere, readPostList);
|
postType, sortType, postFilter, userWhere, readPostList, postEnricher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import eu.toldi.infinityforlemmy.Flair;
|
|||||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||||
import eu.toldi.infinityforlemmy.dto.SubmitPostDTO;
|
import eu.toldi.infinityforlemmy.dto.SubmitPostDTO;
|
||||||
|
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
|
||||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||||
import eu.toldi.infinityforlemmy.utils.UploadImageUtils;
|
import eu.toldi.infinityforlemmy.utils.UploadImageUtils;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
@ -25,22 +26,24 @@ public class SubmitPost {
|
|||||||
public static void submitTextOrLinkPost(Executor executor, Handler handler, Retrofit oauthRetrofit, String accessToken,
|
public static void submitTextOrLinkPost(Executor executor, Handler handler, Retrofit oauthRetrofit, String accessToken,
|
||||||
int communityId, String title, String body, String url,
|
int communityId, String title, String body, String url,
|
||||||
Flair flair, boolean isSpoiler, boolean isNSFW,
|
Flair flair, boolean isSpoiler, boolean isNSFW,
|
||||||
boolean receivePostReplyNotifications, String kind,
|
boolean receivePostReplyNotifications, String kind, PostEnricher postEnricher,
|
||||||
SubmitPostListener submitPostListener) {
|
SubmitPostListener submitPostListener) {
|
||||||
submitPost(executor, handler, oauthRetrofit, accessToken, communityId, title, body,
|
submitPost(executor, handler, oauthRetrofit, accessToken, communityId, title, body,
|
||||||
isNSFW, receivePostReplyNotifications, kind, url, submitPostListener);
|
isNSFW, receivePostReplyNotifications, kind, url, postEnricher, submitPostListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void submitImagePost(Executor executor, Handler handler, RetrofitHolder mRetrofit,
|
public static void submitImagePost(Executor executor, Handler handler, RetrofitHolder mRetrofit,
|
||||||
String accessToken, int communityId, String title, String body, Bitmap image,
|
String accessToken, int communityId, String title, String body, Bitmap image,
|
||||||
Flair flair, boolean isSpoiler, boolean isNSFW,
|
Flair flair, boolean isSpoiler, boolean isNSFW,
|
||||||
boolean receivePostReplyNotifications, SubmitPostListener submitPostListener) {
|
boolean receivePostReplyNotifications, PostEnricher postEnricher,
|
||||||
|
SubmitPostListener submitPostListener) {
|
||||||
try {
|
try {
|
||||||
String imageUrlOrError = UploadImageUtils.uploadImage(mRetrofit, accessToken, image);
|
String imageUrlOrError = UploadImageUtils.uploadImage(mRetrofit, accessToken, image);
|
||||||
if (imageUrlOrError != null && !imageUrlOrError.startsWith("Error: ")) {
|
if (imageUrlOrError != null && !imageUrlOrError.startsWith("Error: ")) {
|
||||||
submitPost(executor, handler, mRetrofit.getRetrofit(), accessToken,
|
submitPost(executor, handler, mRetrofit.getRetrofit(), accessToken,
|
||||||
communityId, title, body, isNSFW,
|
communityId, title, body, isNSFW,
|
||||||
receivePostReplyNotifications, APIUtils.KIND_IMAGE, imageUrlOrError, submitPostListener);
|
receivePostReplyNotifications, APIUtils.KIND_IMAGE, imageUrlOrError,
|
||||||
|
postEnricher, submitPostListener);
|
||||||
} else {
|
} else {
|
||||||
submitPostListener.submitFailed(imageUrlOrError);
|
submitPostListener.submitFailed(imageUrlOrError);
|
||||||
}
|
}
|
||||||
@ -53,17 +56,18 @@ public class SubmitPost {
|
|||||||
public static void submitCrosspost(Executor executor, Handler handler, Retrofit oauthRetrofit, String accessToken,
|
public static void submitCrosspost(Executor executor, Handler handler, Retrofit oauthRetrofit, String accessToken,
|
||||||
int communityId, String title, String crosspostFullname,
|
int communityId, String title, String crosspostFullname,
|
||||||
Flair flair, boolean isSpoiler, boolean isNSFW,
|
Flair flair, boolean isSpoiler, boolean isNSFW,
|
||||||
boolean receivePostReplyNotifications, String kind,
|
boolean receivePostReplyNotifications, String kind, PostEnricher postEnricher,
|
||||||
SubmitPostListener submitPostListener) {
|
SubmitPostListener submitPostListener) {
|
||||||
submitPost(executor, handler, oauthRetrofit, accessToken, communityId, title, crosspostFullname,
|
submitPost(executor, handler, oauthRetrofit, accessToken, communityId, title, crosspostFullname,
|
||||||
isNSFW, receivePostReplyNotifications, kind, null, submitPostListener);
|
isNSFW, receivePostReplyNotifications, kind, null, postEnricher, submitPostListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void submitPost(Executor executor, Handler handler, Retrofit oauthRetrofit, String accessToken,
|
private static void submitPost(Executor executor, Handler handler, Retrofit oauthRetrofit, String accessToken,
|
||||||
int communityId, String title, String content,
|
int communityId, String title, String content,
|
||||||
boolean isNSFW,
|
boolean isNSFW,
|
||||||
boolean receivePostReplyNotifications, String kind,
|
boolean receivePostReplyNotifications, String kind,
|
||||||
@Nullable String posterUrl, SubmitPostListener submitPostListener) {
|
@Nullable String posterUrl, PostEnricher postEnricher,
|
||||||
|
SubmitPostListener submitPostListener) {
|
||||||
LemmyAPI api = oauthRetrofit.create(LemmyAPI.class);
|
LemmyAPI api = oauthRetrofit.create(LemmyAPI.class);
|
||||||
|
|
||||||
|
|
||||||
@ -73,7 +77,7 @@ public class SubmitPost {
|
|||||||
Response<String> response = submitPostCall.execute();
|
Response<String> response = submitPostCall.execute();
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
getSubmittedPost(executor, handler, response.body(), kind, oauthRetrofit, accessToken,
|
getSubmittedPost(executor, handler, response.body(), kind, oauthRetrofit, accessToken,
|
||||||
submitPostListener);
|
postEnricher, submitPostListener);
|
||||||
} else {
|
} else {
|
||||||
submitPostListener.submitFailed(response.message());
|
submitPostListener.submitFailed(response.message());
|
||||||
}
|
}
|
||||||
@ -84,10 +88,10 @@ public class SubmitPost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void getSubmittedPost(Executor executor, Handler handler, String response, String kind,
|
private static void getSubmittedPost(Executor executor, Handler handler, String response, String kind,
|
||||||
Retrofit oauthRetrofit, String accessToken,
|
Retrofit oauthRetrofit, String accessToken, PostEnricher postEnricher,
|
||||||
SubmitPostListener submitPostListener) throws JSONException, IOException {
|
SubmitPostListener submitPostListener) throws JSONException, IOException {
|
||||||
|
|
||||||
ParsePost.parsePost(executor, handler, response, new ParsePost.ParsePostListener() {
|
ParsePost.parsePost(executor, handler, postEnricher, response, new ParsePost.ParsePostListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onParsePostSuccess(Post post) {
|
public void onParsePostSuccess(Post post) {
|
||||||
submitPostListener.submitSuccessful(post);
|
submitPostListener.submitSuccessful(post);
|
||||||
|
@ -54,6 +54,7 @@ import eu.toldi.infinityforlemmy.events.SubmitPollPostEvent;
|
|||||||
import eu.toldi.infinityforlemmy.events.SubmitTextOrLinkPostEvent;
|
import eu.toldi.infinityforlemmy.events.SubmitTextOrLinkPostEvent;
|
||||||
import eu.toldi.infinityforlemmy.post.Post;
|
import eu.toldi.infinityforlemmy.post.Post;
|
||||||
import eu.toldi.infinityforlemmy.post.SubmitPost;
|
import eu.toldi.infinityforlemmy.post.SubmitPost;
|
||||||
|
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
|
||||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||||
import eu.toldi.infinityforlemmy.utils.JSONUtils;
|
import eu.toldi.infinityforlemmy.utils.JSONUtils;
|
||||||
import eu.toldi.infinityforlemmy.utils.NotificationUtils;
|
import eu.toldi.infinityforlemmy.utils.NotificationUtils;
|
||||||
@ -102,6 +103,8 @@ public class SubmitPostService extends Service {
|
|||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
|
@Inject
|
||||||
|
PostEnricher postEnricher;
|
||||||
private Handler handler;
|
private Handler handler;
|
||||||
private ServiceHandler serviceHandler;
|
private ServiceHandler serviceHandler;
|
||||||
|
|
||||||
@ -221,7 +224,7 @@ public class SubmitPostService extends Service {
|
|||||||
String kind) {
|
String kind) {
|
||||||
SubmitPost.submitTextOrLinkPost(mExecutor, handler, newAuthenticatorOauthRetrofit, selectedAccount.getAccessToken(),
|
SubmitPost.submitTextOrLinkPost(mExecutor, handler, newAuthenticatorOauthRetrofit, selectedAccount.getAccessToken(),
|
||||||
communityId, title, body, url, flair, isSpoiler,
|
communityId, title, body, url, flair, isSpoiler,
|
||||||
isNSFW, receivePostReplyNotifications, kind, new SubmitPost.SubmitPostListener() {
|
isNSFW, receivePostReplyNotifications, kind, postEnricher, new SubmitPost.SubmitPostListener() {
|
||||||
@Override
|
@Override
|
||||||
public void submitSuccessful(Post post) {
|
public void submitSuccessful(Post post) {
|
||||||
handler.post(() -> EventBus.getDefault().post(new SubmitTextOrLinkPostEvent(true, post, null)));
|
handler.post(() -> EventBus.getDefault().post(new SubmitTextOrLinkPostEvent(true, post, null)));
|
||||||
@ -243,7 +246,7 @@ public class SubmitPostService extends Service {
|
|||||||
String title, String content, Flair flair, boolean isSpoiler, boolean isNSFW,
|
String title, String content, Flair flair, boolean isSpoiler, boolean isNSFW,
|
||||||
boolean receivePostReplyNotifications) {
|
boolean receivePostReplyNotifications) {
|
||||||
SubmitPost.submitCrosspost(executor, handler, newAuthenticatorOauthRetrofit, selectedAccount.getAccessToken(), communityId, title,
|
SubmitPost.submitCrosspost(executor, handler, newAuthenticatorOauthRetrofit, selectedAccount.getAccessToken(), communityId, title,
|
||||||
content, flair, isSpoiler, isNSFW, receivePostReplyNotifications, APIUtils.KIND_CROSSPOST,
|
content, flair, isSpoiler, isNSFW, receivePostReplyNotifications, APIUtils.KIND_CROSSPOST, postEnricher,
|
||||||
new SubmitPost.SubmitPostListener() {
|
new SubmitPost.SubmitPostListener() {
|
||||||
@Override
|
@Override
|
||||||
public void submitSuccessful(Post post) {
|
public void submitSuccessful(Post post) {
|
||||||
@ -266,7 +269,8 @@ public class SubmitPostService extends Service {
|
|||||||
try {
|
try {
|
||||||
Bitmap resource = Glide.with(this).asBitmap().load(mediaUri).submit().get();
|
Bitmap resource = Glide.with(this).asBitmap().load(mediaUri).submit().get();
|
||||||
SubmitPost.submitImagePost(mExecutor, handler, newAuthenticatorOauthRetrofit,
|
SubmitPost.submitImagePost(mExecutor, handler, newAuthenticatorOauthRetrofit,
|
||||||
selectedAccount.getAccessToken(), communityId, title, body, resource, flair, isSpoiler, isNSFW, receivePostReplyNotifications,
|
selectedAccount.getAccessToken(), communityId, title, body, resource, flair, isSpoiler,
|
||||||
|
isNSFW, receivePostReplyNotifications, postEnricher,
|
||||||
new SubmitPost.SubmitPostListener() {
|
new SubmitPost.SubmitPostListener() {
|
||||||
@Override
|
@Override
|
||||||
public void submitSuccessful(Post post) {
|
public void submitSuccessful(Post post) {
|
||||||
|
@ -20,13 +20,16 @@ public class SiteInfo {
|
|||||||
private boolean enable_nsfw;
|
private boolean enable_nsfw;
|
||||||
private boolean community_creation_admin_only;
|
private boolean community_creation_admin_only;
|
||||||
|
|
||||||
|
private String version;
|
||||||
|
|
||||||
private List<BasicUserInfo> admins;
|
private List<BasicUserInfo> admins;
|
||||||
|
|
||||||
SiteStatistics siteStatistics;
|
SiteStatistics siteStatistics;
|
||||||
|
|
||||||
public SiteInfo(int id, String name, String sidebar, String description, boolean enable_downvotes, boolean enable_nsfw, boolean community_creation_admin_only, List<BasicUserInfo> admins, SiteStatistics siteStatistics) {
|
public SiteInfo(int id, String name, String version, String sidebar, String description, boolean enable_downvotes, boolean enable_nsfw, boolean community_creation_admin_only, List<BasicUserInfo> admins, SiteStatistics siteStatistics) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.version = version;
|
||||||
this.sidebar = sidebar;
|
this.sidebar = sidebar;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.enable_downvotes = enable_downvotes;
|
this.enable_downvotes = enable_downvotes;
|
||||||
@ -72,6 +75,10 @@ public class SiteInfo {
|
|||||||
return siteStatistics;
|
return siteStatistics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
public static SiteInfo parseSiteInfo(String siteInfoJson) {
|
public static SiteInfo parseSiteInfo(String siteInfoJson) {
|
||||||
try {
|
try {
|
||||||
JSONObject siteInfo = new JSONObject(siteInfoJson);
|
JSONObject siteInfo = new JSONObject(siteInfoJson);
|
||||||
@ -84,6 +91,7 @@ public class SiteInfo {
|
|||||||
String sidebar = null;
|
String sidebar = null;
|
||||||
if (site.has("sidebar"))
|
if (site.has("sidebar"))
|
||||||
sidebar = site.getString("sidebar");
|
sidebar = site.getString("sidebar");
|
||||||
|
String version = siteInfo.getString("version");
|
||||||
|
|
||||||
String description = null;
|
String description = null;
|
||||||
if (site.has("description"))
|
if (site.has("description"))
|
||||||
@ -106,7 +114,7 @@ public class SiteInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SiteInfo(id, name, sidebar, description, enable_downvotes, enable_nsfw, community_creation_admin_only, admins, SiteStatistics.parseSiteStatistics(counts));
|
return new SiteInfo(id, name, version, sidebar, description, enable_downvotes, enable_nsfw, community_creation_admin_only, admins, SiteStatistics.parseSiteStatistics(counts));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
|
@ -48,7 +48,7 @@ public class ParseUserData {
|
|||||||
boolean isBot = personJson.getBoolean("bot_account");
|
boolean isBot = personJson.getBoolean("bot_account");
|
||||||
boolean isBanned = personJson.getBoolean("banned");
|
boolean isBanned = personJson.getBoolean("banned");
|
||||||
boolean isLocal = personJson.getBoolean("local");
|
boolean isLocal = personJson.getBoolean("local");
|
||||||
boolean isAdmin = personJson.getBoolean("admin");
|
boolean isAdmin = personJson.optBoolean("admin");
|
||||||
boolean isDeleted = personJson.getBoolean("deleted");
|
boolean isDeleted = personJson.getBoolean("deleted");
|
||||||
|
|
||||||
String description = "";
|
String description = "";
|
||||||
|
@ -5,7 +5,9 @@ import android.util.Base64;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import okhttp3.Interceptor;
|
||||||
import okhttp3.MediaType;
|
import okhttp3.MediaType;
|
||||||
|
import okhttp3.Request;
|
||||||
import okhttp3.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -142,12 +144,6 @@ public class APIUtils {
|
|||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, String> getRedgifsOAuthHeader(String redgifsAccessToken) {
|
|
||||||
Map<String, String> params = new HashMap<>();
|
|
||||||
params.put(APIUtils.AUTHORIZATION_KEY, APIUtils.AUTHORIZATION_BASE + redgifsAccessToken);
|
|
||||||
return params;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static RequestBody getRequestBody(String s) {
|
public static RequestBody getRequestBody(String s) {
|
||||||
return RequestBody.create(s, MediaType.parse("text/plain"));
|
return RequestBody.create(s, MediaType.parse("text/plain"));
|
||||||
}
|
}
|
||||||
@ -159,4 +155,13 @@ public class APIUtils {
|
|||||||
params.put(APIUtils.USER_AGENT_KEY, APIUtils.USER_AGENT);
|
params.put(APIUtils.USER_AGENT_KEY, APIUtils.USER_AGENT);
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Interceptor getOAuthInterceptor(String accessToken) {
|
||||||
|
return chain -> {
|
||||||
|
Request newRequest = chain.request().newBuilder()
|
||||||
|
.addHeader("Authorization", "Bearer " + accessToken)
|
||||||
|
.build();
|
||||||
|
return chain.proceed(newRequest);
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,6 +126,7 @@ public class JSONUtils {
|
|||||||
public static final String Y_KEY = "y";
|
public static final String Y_KEY = "y";
|
||||||
public static final String DEST_KEY = "dest";
|
public static final String DEST_KEY = "dest";
|
||||||
public static final String GIF_KEY = "gif";
|
public static final String GIF_KEY = "gif";
|
||||||
|
public static final String GIFS_KEY = "gifs";
|
||||||
public static final String MAX_EMOJIS_KEY = "max_emojis";
|
public static final String MAX_EMOJIS_KEY = "max_emojis";
|
||||||
public static final String RICHTEXT_KEY = "richtext";
|
public static final String RICHTEXT_KEY = "richtext";
|
||||||
public static final String SUGGESTED_COMMENT_SORT_KEY = "suggested_comment_sort";
|
public static final String SUGGESTED_COMMENT_SORT_KEY = "suggested_comment_sort";
|
||||||
|
@ -359,6 +359,8 @@ public class SharedPreferencesUtils {
|
|||||||
public static final String CURRENT_ACCOUNT_SHARED_PREFERENCES_FILE = "eu.toldi.infinityforlemmy.current_account";
|
public static final String CURRENT_ACCOUNT_SHARED_PREFERENCES_FILE = "eu.toldi.infinityforlemmy.current_account";
|
||||||
public static final String ACCOUNT_NAME = "account_name";
|
public static final String ACCOUNT_NAME = "account_name";
|
||||||
public static final String ACCESS_TOKEN = "access_token";
|
public static final String ACCESS_TOKEN = "access_token";
|
||||||
|
|
||||||
|
public static final String BEARER_TOKEN_AUTH = "bearer_token_auth";
|
||||||
public static final String ACCOUNT_IMAGE_URL = "account_image_url";
|
public static final String ACCOUNT_IMAGE_URL = "account_image_url";
|
||||||
public static final String REDGIFS_ACCESS_TOKEN = "redgifs_access_token";
|
public static final String REDGIFS_ACCESS_TOKEN = "redgifs_access_token";
|
||||||
|
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
package eu.toldi.infinityforlemmy.post.enrich
|
||||||
|
|
||||||
|
import eu.toldi.infinityforlemmy.post.Post
|
||||||
|
|
||||||
|
class CompositePostEnricher(private val enrichers: Set<PostEnricher>) : PostEnricher {
|
||||||
|
override fun enrich(posts: Collection<Post>) {
|
||||||
|
for (enricher in enrichers) {
|
||||||
|
enricher.enrich(posts)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package eu.toldi.infinityforlemmy.post.enrich
|
||||||
|
|
||||||
|
import eu.toldi.infinityforlemmy.post.Post
|
||||||
|
|
||||||
|
interface PostEnricher {
|
||||||
|
fun enrich(posts: Collection<Post>)
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
package eu.toldi.infinityforlemmy.post.enrich
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
|
import eu.toldi.infinityforlemmy.apis.RedgifsAPI
|
||||||
|
import eu.toldi.infinityforlemmy.post.Post
|
||||||
|
import eu.toldi.infinityforlemmy.post.Post.Preview
|
||||||
|
import eu.toldi.infinityforlemmy.utils.JSONUtils
|
||||||
|
import org.json.JSONException
|
||||||
|
import org.json.JSONObject
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
|
class RedGifsPostEnricher(private val redgifsAPI: RedgifsAPI) : PostEnricher {
|
||||||
|
override fun enrich(posts: Collection<Post>) {
|
||||||
|
val redGifsPosts = posts.filter { it.isRedgifs && it.previews.isEmpty() }
|
||||||
|
.groupBy { it.gfycatId }
|
||||||
|
|
||||||
|
if (redGifsPosts.isEmpty()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
val response = redgifsAPI.getRedgifsMultipleData(redGifsPosts.keys.joinToString(",")).execute()
|
||||||
|
val body = response.body()
|
||||||
|
if (response.isSuccessful && body != null) {
|
||||||
|
try {
|
||||||
|
val gifsJson = JSONObject(body).getJSONArray(JSONUtils.GIFS_KEY)
|
||||||
|
for (i in 0 until gifsJson.length()) {
|
||||||
|
val gifJson = gifsJson.getJSONObject(i)
|
||||||
|
val id = gifJson.getString(JSONUtils.ID_KEY)
|
||||||
|
val width = gifJson.getInt(JSONUtils.WIDTH_KEY)
|
||||||
|
val height = gifJson.getInt(JSONUtils.HEIGHT_KEY)
|
||||||
|
val thumbnail = gifJson.getJSONObject(JSONUtils.URLS_KEY)
|
||||||
|
.getString(JSONUtils.THUMBNAIL_KEY)
|
||||||
|
|
||||||
|
val previews = ArrayList(listOf(Preview(thumbnail, width, height, null, null)))
|
||||||
|
|
||||||
|
redGifsPosts[id]?.forEach {
|
||||||
|
it.previews = previews
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (e: JSONException) {
|
||||||
|
Log.w(TAG, "Failed to parse JSON", e)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.w(TAG, "Failed fetch data. Status code ${response.code()}")
|
||||||
|
}
|
||||||
|
} catch (e: IOException) {
|
||||||
|
Log.w(TAG, "Failed fetch data", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val TAG = "RedGifsPostEnricher"
|
||||||
|
}
|
||||||
|
}
|
@ -543,17 +543,17 @@
|
|||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="settings_default_sort_time_values">
|
<string-array name="settings_default_sort_time_values">
|
||||||
<item>TopHour</item>
|
<item>hour</item>
|
||||||
<item>TopSixHour</item>
|
<item>SixHour</item>
|
||||||
<item>TopTwelveHour</item>
|
<item>TwelveHour</item>
|
||||||
<item>TopDay</item>
|
<item>day</item>
|
||||||
<item>TopWeek</item>
|
<item>week</item>
|
||||||
<item>TopMonth</item>
|
<item>month</item>
|
||||||
<item>TopThreeMonths</item>
|
<item>ThreeMonths</item>
|
||||||
<item>TopSixMonths</item>
|
<item>SixMonths</item>
|
||||||
<item>TopNineMonths</item>
|
<item>NineMonths</item>
|
||||||
<item>TopYear</item>
|
<item>year</item>
|
||||||
<item>TopAll</item>
|
<item>all</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="settings_default_search_result_tab">
|
<string-array name="settings_default_search_result_tab">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user