mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-02-07 07:04:44 +01:00
Compare commits
No commits in common. "28617cf9a820a41982f8974241b1ddf4c2181493" and "29547f4750efa57c1ddae4ae23db42682d9e3b9c" have entirely different histories.
28617cf9a8
...
29547f4750
@ -196,7 +196,6 @@ 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, PostEnricherModule.class})
|
@Component(modules = {AppModule.class, NetworkModule.class})
|
||||||
public interface AppComponent {
|
public interface AppComponent {
|
||||||
void inject(MainActivity mainActivity);
|
void inject(MainActivity mainActivity);
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
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;
|
||||||
@ -10,7 +12,9 @@ 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;
|
||||||
@ -40,12 +44,14 @@ public class FetchGfycatOrRedgifsVideoLinks {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void fetchRedgifsVideoLinks(Executor executor, Handler handler, Retrofit redgifsRetrofit,
|
public static void fetchRedgifsVideoLinks(Context context, 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(gfycatId).execute();
|
Response<String> response = redgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(APIUtils.getRedgifsOAuthHeader(currentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "")),
|
||||||
|
gfycatId, APIUtils.USER_AGENT).execute();
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
parseRedgifsVideoLinks(handler, response.body(), fetchGfycatOrRedgifsVideoLinksListener);
|
parseRedgifsVideoLinks(handler, response.body(), fetchGfycatOrRedgifsVideoLinksListener);
|
||||||
} else {
|
} else {
|
||||||
|
@ -11,16 +11,6 @@ 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;
|
||||||
@ -28,11 +18,15 @@ 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;
|
||||||
@ -44,8 +38,6 @@ 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;
|
||||||
@ -63,9 +55,6 @@ 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() {
|
||||||
@ -170,9 +159,6 @@ 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,7 +9,6 @@ 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;
|
||||||
@ -38,8 +37,7 @@ 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()
|
||||||
@ -47,7 +45,6 @@ abstract class NetworkModule {
|
|||||||
.header("User-Agent", APIUtils.USER_AGENT)
|
.header("User-Agent", APIUtils.USER_AGENT)
|
||||||
.build()
|
.build()
|
||||||
))
|
))
|
||||||
.addInterceptor(redGifsAuthenticator)
|
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,12 +178,6 @@ 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
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
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,6 +14,7 @@ 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;
|
||||||
@ -21,8 +22,6 @@ 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) {
|
||||||
@ -61,17 +60,7 @@ 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 {
|
||||||
if (!chain.request().url().host().endsWith(REDGIFS_HOST)) {
|
Response response = chain.proceed(chain.request());
|
||||||
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) {
|
||||||
@ -85,21 +74,13 @@ public class RedgifsAccessTokenAuthenticator implements Interceptor {
|
|||||||
String newAccessToken = refreshAccessToken();
|
String newAccessToken = refreshAccessToken();
|
||||||
if (!newAccessToken.equals("")) {
|
if (!newAccessToken.equals("")) {
|
||||||
response.close();
|
response.close();
|
||||||
return chain.proceed(
|
return chain.proceed(response.request().newBuilder().headers(Headers.of(APIUtils.getRedgifsOAuthHeader(newAccessToken))).build());
|
||||||
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(
|
return chain.proceed(response.request().newBuilder().headers(Headers.of(APIUtils.getRedgifsOAuthHeader(accessTokenFromSharedPreferences))).build());
|
||||||
chain.request().newBuilder()
|
|
||||||
.addHeader(APIUtils.AUTHORIZATION_KEY, APIUtils.AUTHORIZATION_BASE + accessTokenFromSharedPreferences)
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
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;
|
||||||
@ -15,14 +12,8 @@ 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;
|
||||||
}
|
}
|
||||||
@ -42,7 +33,6 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,18 +46,4 @@ 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,6 @@ 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;
|
||||||
|
|
||||||
@ -84,9 +83,6 @@ 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) {
|
||||||
@ -218,7 +214,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, postEnricher, new FetchPost.FetchPostListener() {
|
FetchPost.fetchPost(mExecutor, new Handler(), mRetrofit.getRetrofit(), segments.get(segments.size() - 1), mAccessToken, new FetchPost.FetchPostListener() {
|
||||||
@Override
|
@Override
|
||||||
public void fetchPostSuccess(Post post) {
|
public void fetchPostSuccess(Post post) {
|
||||||
|
|
||||||
|
@ -81,7 +81,6 @@ 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;
|
||||||
@ -152,8 +151,6 @@ 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
|
||||||
@ -595,7 +592,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
|
|||||||
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, postEnricher);
|
LinkedHashSet<Post> newPosts = ParsePost.parsePostsSync(responseString, -1, postFilter, readPostList);
|
||||||
if (newPosts == null) {
|
if (newPosts == null) {
|
||||||
handler.post(() -> {
|
handler.post(() -> {
|
||||||
loadingMorePostsStatus = LoadingMorePostsStatus.NO_MORE_POSTS;
|
loadingMorePostsStatus = LoadingMorePostsStatus.NO_MORE_POSTS;
|
||||||
@ -677,7 +674,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, postEnricher);
|
LinkedHashSet<Post> newPosts = ParsePost.parsePostsSync(responseString, -1, postFilter, null);
|
||||||
if (newPosts == null || newPosts.isEmpty()) {
|
if (newPosts == null || newPosts.isEmpty()) {
|
||||||
handler.post(() -> {
|
handler.post(() -> {
|
||||||
loadingMorePostsStatus = LoadingMorePostsStatus.NO_MORE_POSTS;
|
loadingMorePostsStatus = LoadingMorePostsStatus.NO_MORE_POSTS;
|
||||||
|
@ -108,7 +108,6 @@ 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;
|
||||||
@ -223,6 +222,10 @@ 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;
|
||||||
|
|
||||||
@ -232,9 +235,6 @@ 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(mExecutor, new Handler(), redgifsRetrofit,
|
FetchGfycatOrRedgifsVideoLinks.fetchRedgifsVideoLinks(this, mExecutor, new Handler(), redgifsRetrofit,
|
||||||
gfycatId, new FetchGfycatOrRedgifsVideoLinks.FetchGfycatOrRedgifsVideoLinksListener() {
|
mCurrentAccountSharedPreferences, 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,
|
||||||
postEnricher, new FetchPost.FetchPostListener() {
|
new FetchPost.FetchPostListener() {
|
||||||
@Override
|
@Override
|
||||||
public void fetchPostSuccess(Post post) {
|
public void fetchPostSuccess(Post post) {
|
||||||
if (post.isGfycat()) {
|
if (post.isGfycat()) {
|
||||||
|
@ -139,6 +139,7 @@ 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;
|
||||||
@ -226,7 +227,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 sharedPreferences, SharedPreferences currentAccountSharedPreferences,
|
||||||
SharedPreferences nsfwAndSpoilerSharedPreferences,
|
SharedPreferences nsfwAndSpoilerSharedPreferences,
|
||||||
ExoCreator exoCreator, Callback callback) {
|
ExoCreator exoCreator, Callback callback) {
|
||||||
super(DIFF_CALLBACK);
|
super(DIFF_CALLBACK);
|
||||||
@ -234,6 +235,7 @@ 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;
|
||||||
@ -696,7 +698,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(post.getGfycatId());
|
mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(APIUtils.getRedgifsOAuthHeader(mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "")), post.getGfycatId(), APIUtils.USER_AGENT);
|
||||||
FetchGfycatOrRedgifsVideoLinks.fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(mExecutor, new Handler(),
|
FetchGfycatOrRedgifsVideoLinks.fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(mExecutor, new Handler(),
|
||||||
((PostVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall,
|
((PostVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall,
|
||||||
post.isGfycat(), mAutomaticallyTryRedgifs,
|
post.isGfycat(), mAutomaticallyTryRedgifs,
|
||||||
@ -873,7 +875,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(post.getGfycatId());
|
mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(APIUtils.getRedgifsOAuthHeader(mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "")), post.getGfycatId(), APIUtils.USER_AGENT);
|
||||||
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(mPost.getGfycatId());
|
mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(APIUtils.getRedgifsOAuthHeader(mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "")), mPost.getGfycatId(), APIUtils.USER_AGENT);
|
||||||
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(post.getGfycatId());
|
mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(APIUtils.getRedgifsOAuthHeader(mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "")), post.getGfycatId(), APIUtils.USER_AGENT);
|
||||||
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(post.getGfycatId());
|
mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(APIUtils.getRedgifsOAuthHeader(mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "")), post.getGfycatId(), APIUtils.USER_AGENT);
|
||||||
FetchGfycatOrRedgifsVideoLinks.fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(mExecutor, new Handler(),
|
FetchGfycatOrRedgifsVideoLinks.fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(mExecutor, new Handler(),
|
||||||
((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall,
|
((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall,
|
||||||
post.isGfycat(), mAutomaticallyTryRedgifs,
|
post.isGfycat(), mAutomaticallyTryRedgifs,
|
||||||
|
@ -6,16 +6,14 @@ 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(@Path("id") String id);
|
Call<String> getRedgifsData(@HeaderMap Map<String, String> headers, @Path("id") String id, @Query("user-agent") String userAgent);
|
||||||
|
|
||||||
@GET("/v2/gifs")
|
|
||||||
Call<String> getRedgifsMultipleData(@Query("ids") String ids);
|
|
||||||
|
|
||||||
@FormUrlEncoded
|
@FormUrlEncoded
|
||||||
@POST("/v2/oauth/client")
|
@POST("/v2/oauth/client")
|
||||||
|
@ -2,7 +2,6 @@ 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;
|
||||||
|
|
||||||
@ -26,31 +25,18 @@ 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,7 +124,6 @@ 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;
|
||||||
@ -179,6 +178,9 @@ 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
|
||||||
@ -196,8 +198,6 @@ 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, mNsfwAndSpoilerSharedPreferences,
|
mSharedPreferences, mCurrentAccountSharedPreferences, mNsfwAndSpoilerSharedPreferences,
|
||||||
mExoCreator, new HistoryPostRecyclerViewAdapter.Callback() {
|
mExoCreator, new HistoryPostRecyclerViewAdapter.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void typeChipClicked(int filter) {
|
public void typeChipClicked(int filter) {
|
||||||
@ -654,10 +654,15 @@ 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,7 +135,6 @@ 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;
|
||||||
@ -223,8 +222,6 @@ 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;
|
||||||
@ -1224,36 +1221,30 @@ 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, postEnricher))
|
query, trendingSource, postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
|
||||||
.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,
|
mPostHistorySharedPreferences, postType, sortType, postFilter, readPosts, subredditName)).get(PostViewModel.class);
|
||||||
postEnricher))
|
|
||||||
.get(PostViewModel.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bindPostViewModel();
|
bindPostViewModel();
|
||||||
@ -1265,27 +1256,26 @@ 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, postEnricher)).get(PostViewModel.class);
|
postType, sortType, postFilter, readPosts)).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, postEnricher)).get(PostViewModel.class);
|
postFilter, readPosts)).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, postEnricher)).get(PostViewModel.class);
|
postType, sortType, postFilter, readPosts)).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, postEnricher)).get(PostViewModel.class);
|
where, readPosts)).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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +112,6 @@ 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;
|
||||||
@ -201,8 +200,6 @@ 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
|
||||||
@ -1332,7 +1329,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,
|
||||||
postEnricher, new FetchPost.FetchPostListener() {
|
new FetchPost.FetchPostListener() {
|
||||||
@Override
|
@Override
|
||||||
public void fetchPostSuccess(Post post) {
|
public void fetchPostSuccess(Post post) {
|
||||||
if (!isAdded()) {
|
if (!isAdded()) {
|
||||||
@ -1591,7 +1588,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,
|
||||||
postEnricher, new FetchPost.FetchPostListener() {
|
new FetchPost.FetchPostListener() {
|
||||||
@Override
|
@Override
|
||||||
public void fetchPostSuccess(Post post) {
|
public void fetchPostSuccess(Post post) {
|
||||||
if (isAdded()) {
|
if (isAdded()) {
|
||||||
|
@ -8,7 +8,6 @@ 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;
|
||||||
@ -16,7 +15,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,
|
||||||
PostEnricher postEnricher, FetchPostListener fetchPostListener) {
|
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);
|
||||||
@ -25,7 +24,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, postEnricher, response.body(), new ParsePost.ParsePostListener() {
|
ParsePost.parsePost(executor, handler, response.body(), new ParsePost.ParsePostListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onParsePostSuccess(Post post) {
|
public void onParsePostSuccess(Post post) {
|
||||||
fetchPostListener.fetchPostSuccess(post);
|
fetchPostListener.fetchPostSuccess(post);
|
||||||
|
@ -19,7 +19,6 @@ 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;
|
||||||
@ -40,11 +39,10 @@ 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, PostEnricher postEnricher) {
|
String username, int postType, PostFilter postFilter) {
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.redditDataRoomDatabase = redditDataRoomDatabase;
|
this.redditDataRoomDatabase = redditDataRoomDatabase;
|
||||||
@ -54,7 +52,6 @@ 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
|
||||||
@ -95,7 +92,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, postEnricher);
|
LinkedHashSet<Post> newPosts = ParsePost.parsePostsSync(responseString, -1, postFilter, null);
|
||||||
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,7 +17,6 @@ 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;
|
||||||
|
|
||||||
@ -30,7 +29,6 @@ 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;
|
||||||
|
|
||||||
@ -38,7 +36,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, PostEnricher postEnricher) {
|
int postType, PostFilter postFilter) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.redditDataRoomDatabase = redditDataRoomDatabase;
|
this.redditDataRoomDatabase = redditDataRoomDatabase;
|
||||||
@ -47,12 +45,11 @@ 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::returnPagingSource);
|
Pager<String, Post> pager = new Pager<>(new PagingConfig(25, 25, false), this::returnPagingSoruce);
|
||||||
|
|
||||||
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)));
|
||||||
}
|
}
|
||||||
@ -61,9 +58,19 @@ public class HistoryPostViewModel extends ViewModel {
|
|||||||
return posts;
|
return posts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HistoryPostPagingSource returnPagingSource() {
|
public HistoryPostPagingSource returnPagingSoruce() {
|
||||||
return new HistoryPostPagingSource(retrofit, executor, redditDataRoomDatabase, accessToken, accountName,
|
HistoryPostPagingSource paging3PagingSource;
|
||||||
sharedPreferences, accountName, postType, postFilter, postEnricher);
|
switch (postType) {
|
||||||
|
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) {
|
||||||
@ -79,11 +86,10 @@ 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, PostEnricher postEnricher) {
|
PostFilter postFilter) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.redditDataRoomDatabase = redditDataRoomDatabase;
|
this.redditDataRoomDatabase = redditDataRoomDatabase;
|
||||||
@ -92,14 +98,18 @@ 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,7 +34,6 @@ 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;
|
||||||
@ -46,8 +45,7 @@ import eu.toldi.infinityforlemmy.utils.Utils;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public class ParsePost {
|
public class ParsePost {
|
||||||
public static LinkedHashSet<Post> parsePostsSync(String response, int nPosts, PostFilter postFilter,
|
public static LinkedHashSet<Post> parsePostsSync(String response, int nPosts, PostFilter postFilter, List<String> readPostList) {
|
||||||
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);
|
||||||
@ -82,8 +80,6 @@ public class ParsePost {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
postEnricher.enrich(newPosts);
|
|
||||||
|
|
||||||
return newPosts;
|
return newPosts;
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -91,9 +87,21 @@ 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");
|
||||||
@ -103,7 +111,6 @@ 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();
|
||||||
@ -181,7 +188,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.optBoolean("admin") ? "admin" : "";
|
String distinguished = (creator.getBoolean("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")) {
|
||||||
|
@ -21,7 +21,6 @@ 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.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,7 +57,6 @@ 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;
|
||||||
@ -66,8 +64,7 @@ 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;
|
||||||
@ -79,14 +76,13 @@ 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, PostEnricher postEnricher) {
|
List<String> readPostList) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
@ -118,14 +114,13 @@ 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, PostEnricher postEnricher) {
|
String where, List<String> readPostList) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
@ -138,14 +133,13 @@ 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, PostEnricher postEnricher) {
|
SortType sortType, PostFilter postFilter, List<String> readPostList) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
@ -158,9 +152,8 @@ 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;
|
||||||
this.readPostList = readPostList;
|
|
||||||
this.postEnricher = postEnricher;
|
|
||||||
postLinkedHashSet = new LinkedHashSet<>();
|
postLinkedHashSet = new LinkedHashSet<>();
|
||||||
|
this.readPostList = readPostList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -197,7 +190,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
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, postEnricher);
|
LinkedHashSet<Post> newPosts = ParsePost.parsePostsSync(responseString, -1, postFilter, readPostList);
|
||||||
|
|
||||||
if (newPosts == null) {
|
if (newPosts == null) {
|
||||||
return new LoadResult.Error<>(new Exception("Error parsing posts"));
|
return new LoadResult.Error<>(new Exception("Error parsing posts"));
|
||||||
|
@ -23,7 +23,6 @@ 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;
|
||||||
|
|
||||||
@ -42,7 +41,6 @@ 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;
|
||||||
@ -55,7 +53,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, PostEnricher postEnricher) {
|
SortType sortType, PostFilter postFilter, List<String> readPostList, String option) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
@ -67,7 +65,6 @@ 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);
|
||||||
@ -98,7 +95,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, PostEnricher postEnricher) {
|
SortType sortType, PostFilter postFilter, List<String> readPostList) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
@ -110,7 +107,6 @@ 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);
|
||||||
@ -143,7 +139,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, PostEnricher postEnricher) {
|
List<String> readPostList) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
@ -156,7 +152,6 @@ 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);
|
||||||
@ -188,7 +183,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, PostEnricher postEnricher) {
|
List<String> readPostList) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
@ -202,7 +197,6 @@ 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);
|
||||||
@ -244,25 +238,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, postEnricher);
|
postFilter, readPostList,name);
|
||||||
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, postEnricher);
|
sortType, postFilter, readPostList);
|
||||||
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, postEnricher);
|
postType, sortType, postFilter, readPostList);
|
||||||
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, postEnricher);
|
sortType, postFilter, userWhere, readPostList);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return paging3PagingSource;
|
return paging3PagingSource;
|
||||||
@ -297,12 +291,11 @@ 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, PostEnricher postEnricher) {
|
PostFilter postFilter, List<String> readPostList, String option) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
@ -315,13 +308,12 @@ 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, PostEnricher postEnricher) {
|
PostFilter postFilter, List<String> readPostList) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.retrofit = retrofit;
|
this.retrofit = retrofit;
|
||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
@ -334,15 +326,13 @@ 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;
|
||||||
@ -356,14 +346,12 @@ 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;
|
||||||
@ -378,23 +366,19 @@ 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 concatenatedSubredditNames, int postType, SortType sortType, PostFilter postFilter, String opt) {
|
||||||
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
|
||||||
@ -403,23 +387,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, postEnricher);
|
sortType, postFilter, readPostList,name);
|
||||||
} 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, postEnricher);
|
trendingSource, postType, sortType, postFilter, readPostList);
|
||||||
} 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, postEnricher);
|
postType, sortType, postFilter, readPostList);
|
||||||
} 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, postEnricher);
|
postFilter, null);
|
||||||
} 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, postEnricher);
|
postType, sortType, postFilter, userWhere, readPostList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ 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;
|
||||||
@ -26,24 +25,22 @@ 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, PostEnricher postEnricher,
|
boolean receivePostReplyNotifications, String kind,
|
||||||
SubmitPostListener submitPostListener) {
|
SubmitPostListener submitPostListener) {
|
||||||
submitPost(executor, handler, oauthRetrofit, accessToken, communityId, title, body,
|
submitPost(executor, handler, oauthRetrofit, accessToken, communityId, title, body,
|
||||||
isNSFW, receivePostReplyNotifications, kind, url, postEnricher, submitPostListener);
|
isNSFW, receivePostReplyNotifications, kind, url, 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, PostEnricher postEnricher,
|
boolean receivePostReplyNotifications, SubmitPostListener submitPostListener) {
|
||||||
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,
|
receivePostReplyNotifications, APIUtils.KIND_IMAGE, imageUrlOrError, submitPostListener);
|
||||||
postEnricher, submitPostListener);
|
|
||||||
} else {
|
} else {
|
||||||
submitPostListener.submitFailed(imageUrlOrError);
|
submitPostListener.submitFailed(imageUrlOrError);
|
||||||
}
|
}
|
||||||
@ -56,18 +53,17 @@ 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, PostEnricher postEnricher,
|
boolean receivePostReplyNotifications, String kind,
|
||||||
SubmitPostListener submitPostListener) {
|
SubmitPostListener submitPostListener) {
|
||||||
submitPost(executor, handler, oauthRetrofit, accessToken, communityId, title, crosspostFullname,
|
submitPost(executor, handler, oauthRetrofit, accessToken, communityId, title, crosspostFullname,
|
||||||
isNSFW, receivePostReplyNotifications, kind, null, postEnricher, submitPostListener);
|
isNSFW, receivePostReplyNotifications, kind, null, 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, PostEnricher postEnricher,
|
@Nullable String posterUrl, SubmitPostListener submitPostListener) {
|
||||||
SubmitPostListener submitPostListener) {
|
|
||||||
LemmyAPI api = oauthRetrofit.create(LemmyAPI.class);
|
LemmyAPI api = oauthRetrofit.create(LemmyAPI.class);
|
||||||
|
|
||||||
|
|
||||||
@ -77,7 +73,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,
|
||||||
postEnricher, submitPostListener);
|
submitPostListener);
|
||||||
} else {
|
} else {
|
||||||
submitPostListener.submitFailed(response.message());
|
submitPostListener.submitFailed(response.message());
|
||||||
}
|
}
|
||||||
@ -88,10 +84,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, PostEnricher postEnricher,
|
Retrofit oauthRetrofit, String accessToken,
|
||||||
SubmitPostListener submitPostListener) throws JSONException, IOException {
|
SubmitPostListener submitPostListener) throws JSONException, IOException {
|
||||||
|
|
||||||
ParsePost.parsePost(executor, handler, postEnricher, response, new ParsePost.ParsePostListener() {
|
ParsePost.parsePost(executor, handler, response, new ParsePost.ParsePostListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onParsePostSuccess(Post post) {
|
public void onParsePostSuccess(Post post) {
|
||||||
submitPostListener.submitSuccessful(post);
|
submitPostListener.submitSuccessful(post);
|
||||||
|
@ -54,7 +54,6 @@ 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;
|
||||||
@ -103,8 +102,6 @@ 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;
|
||||||
|
|
||||||
@ -224,7 +221,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, postEnricher, new SubmitPost.SubmitPostListener() {
|
isNSFW, receivePostReplyNotifications, kind, 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)));
|
||||||
@ -246,7 +243,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, postEnricher,
|
content, flair, isSpoiler, isNSFW, receivePostReplyNotifications, APIUtils.KIND_CROSSPOST,
|
||||||
new SubmitPost.SubmitPostListener() {
|
new SubmitPost.SubmitPostListener() {
|
||||||
@Override
|
@Override
|
||||||
public void submitSuccessful(Post post) {
|
public void submitSuccessful(Post post) {
|
||||||
@ -269,8 +266,7 @@ 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,
|
selectedAccount.getAccessToken(), communityId, title, body, resource, flair, isSpoiler, isNSFW, receivePostReplyNotifications,
|
||||||
isNSFW, receivePostReplyNotifications, postEnricher,
|
|
||||||
new SubmitPost.SubmitPostListener() {
|
new SubmitPost.SubmitPostListener() {
|
||||||
@Override
|
@Override
|
||||||
public void submitSuccessful(Post post) {
|
public void submitSuccessful(Post post) {
|
||||||
|
@ -20,16 +20,13 @@ 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 version, 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 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;
|
||||||
@ -75,10 +72,6 @@ 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);
|
||||||
@ -91,7 +84,6 @@ 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"))
|
||||||
@ -114,7 +106,7 @@ public class SiteInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SiteInfo(id, name, version, sidebar, description, enable_downvotes, enable_nsfw, community_creation_admin_only, admins, SiteStatistics.parseSiteStatistics(counts));
|
return new SiteInfo(id, name, 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.optBoolean("admin");
|
boolean isAdmin = personJson.getBoolean("admin");
|
||||||
boolean isDeleted = personJson.getBoolean("deleted");
|
boolean isDeleted = personJson.getBoolean("deleted");
|
||||||
|
|
||||||
String description = "";
|
String description = "";
|
||||||
|
@ -5,9 +5,7 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -144,6 +142,12 @@ 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"));
|
||||||
}
|
}
|
||||||
@ -155,13 +159,4 @@ 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,7 +126,6 @@ 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,8 +359,6 @@ 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";
|
||||||
|
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package eu.toldi.infinityforlemmy.post.enrich
|
|
||||||
|
|
||||||
import eu.toldi.infinityforlemmy.post.Post
|
|
||||||
|
|
||||||
interface PostEnricher {
|
|
||||||
fun enrich(posts: Collection<Post>)
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
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"
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user