mirror of
				https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
				synced 2025-11-04 02:39:09 +01:00 
			
		
		
		
	Compare commits
	
		
			28 Commits
		
	
	
		
			v0.1.1
			...
			reproducib
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					134c895cd4 | ||
| 
						 | 
					ec6567b9b2 | ||
| 
						 | 
					40fa3a1987 | ||
| 
						 | 
					05123c7068 | ||
| 
						 | 
					908f294130 | ||
| 
						 | 
					95408f8125 | ||
| 
						 | 
					6d5ba059f8 | ||
| 
						 | 
					ecdd9da9c8 | ||
| 
						 | 
					1c17e6b7d2 | ||
| 
						 | 
					9f60eca225 | ||
| 
						 | 
					9deba8b10e | ||
| 
						 | 
					05948d74f4 | ||
| 
						 | 
					1007be50f8 | ||
| 
						 | 
					28617cf9a8 | ||
| 
						 | 
					5d2d43eebc | ||
| 
						 | 
					f2b2525823 | ||
| 
						 | 
					29547f4750 | ||
| 
						 | 
					af63bba54a | ||
| 
						 | 
					caf4f177d2 | ||
| 
						 | 
					1e67b34440 | ||
| 
						 | 
					67afcd7e88 | ||
| 
						 | 
					9406f29562 | ||
| 
						 | 
					b626c5fb73 | ||
| 
						 | 
					0393ff6e77 | ||
| 
						 | 
					30ecc17d55 | ||
| 
						 | 
					7c5f184cc8 | ||
| 
						 | 
					d5fff14cb0 | ||
| 
						 | 
					5cdda037b2 | 
							
								
								
									
										
											BIN
										
									
								
								.assets/google-play-badge.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								.assets/google-play-badge.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 4.8 KiB  | 
@@ -2,13 +2,14 @@ steps:
 | 
			
		||||
  build:
 | 
			
		||||
    image: alvrme/alpine-android:android-33-jdk11
 | 
			
		||||
    commands:
 | 
			
		||||
      - apk add --no-cache python3
 | 
			
		||||
      - ./gradlew :app:assembleRelease
 | 
			
		||||
    when:
 | 
			
		||||
      path: [ app/**, build.gradle ]
 | 
			
		||||
  sign:
 | 
			
		||||
    image: alvrme/alpine-android:android-33-jdk11
 | 
			
		||||
    commands:
 | 
			
		||||
      - ./scripts/apk-sign.sh LemmInfinity-signed.apk app/build/outputs/apk/release/app-release-unsigned.apk
 | 
			
		||||
      - ./scripts/apk-sign.sh Eternity-signed.apk app/build/outputs/apk/release/app-release-unsigned.apk
 | 
			
		||||
    secrets: [ APK_KS_PASS, APK_KS, APK_KS_ALIAS ]
 | 
			
		||||
    when:
 | 
			
		||||
      event: [ tag ]
 | 
			
		||||
@@ -17,7 +18,7 @@ steps:
 | 
			
		||||
    settings:
 | 
			
		||||
      base_url: https://codeberg.org
 | 
			
		||||
      files:
 | 
			
		||||
        - LemmInfinity-signed.apk
 | 
			
		||||
        - Eternity-signed.apk
 | 
			
		||||
      api_key:
 | 
			
		||||
        from_secret: GITEA_ACCESS_TOKEN
 | 
			
		||||
      target: main
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,7 @@ steps:
 | 
			
		||||
  build:
 | 
			
		||||
    image: alvrme/alpine-android:android-33-jdk11
 | 
			
		||||
    commands:
 | 
			
		||||
      - apk add --no-cache python3
 | 
			
		||||
      - ./gradlew :app:assembleNightly
 | 
			
		||||
  sign:
 | 
			
		||||
    image: alvrme/alpine-android:android-33-jdk11
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										20
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								README.md
									
									
									
									
									
								
							@@ -10,22 +10,28 @@ A Lemmy client for Android written in Java. It's a fork of the [Infinity for Red
 | 
			
		||||
 | 
			
		||||
<br>
 | 
			
		||||
<div align="center">
 | 
			
		||||
<img src="https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy/raw/branch/master/fastlane/metadata/android/en-US/images/icon.png" width=256>
 | 
			
		||||
<img src="https://codeberg.org/Bazsalanszky/Eternity/raw/branch/master/fastlane/metadata/android/en-US/images/icon.png" width=256>
 | 
			
		||||
 | 
			
		||||
[](https://ci.codeberg.org/repos/12474)
 | 
			
		||||
[](https://liberapay.com/Bazsalanszky)
 | 
			
		||||
 | 
			
		||||
<a href="https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy/issues">Report a Bug</a>
 | 
			
		||||
<a href="https://codeberg.org/Bazsalanszky/Eternity/issues">Report a Bug</a>
 | 
			
		||||
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<div align="center">
 | 
			
		||||
<a href="https://play.google.com/store/apps/details?id=eu.toldi.infinityforlemmy">
 | 
			
		||||
    <img src="./.assets/google-play-badge.png" height="80">
 | 
			
		||||
</a>
 | 
			
		||||
<a href="https://apt.izzysoft.de/fdroid/index/apk/eu.toldi.infinityforlemmy">
 | 
			
		||||
    <img src="./.assets/IzzyOnDroid.png" height="80">
 | 
			
		||||
</a>
 | 
			
		||||
<a href="https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy/releases/">
 | 
			
		||||
<a href="https://codeberg.org/Bazsalanszky/Eternity/releases/">
 | 
			
		||||
    <img src="./.assets/codeberg.png" height="80">
 | 
			
		||||
</a>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
---
 | 
			
		||||
@@ -68,17 +74,17 @@ Don't forget to give the project a star! Thanks again!
 | 
			
		||||
 | 
			
		||||
You can alos help Eternity by translating it to your native langugage! Translations are done via [Weblate](https://translate.codeberg.org/projects/infinity-for-lemmy/app/)!
 | 
			
		||||
 | 
			
		||||
[](https://translate.codeberg.org/engage/infinity-for-lemmy/)
 | 
			
		||||
[](https://translate.codeberg.org/engage/Eternity/)
 | 
			
		||||
 | 
			
		||||
### Reporting bugs
 | 
			
		||||
 | 
			
		||||
You can also contribute by [reporting bugs](https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy/issues)
 | 
			
		||||
You can also contribute by [reporting bugs](https://codeberg.org/Bazsalanszky/Eternity/issues)
 | 
			
		||||
 | 
			
		||||
<p align="right">(<a href="#top">back to top</a>)</p>
 | 
			
		||||
 | 
			
		||||
## License
 | 
			
		||||
 | 
			
		||||
Distributed under the AGPL-3.0 License. See <a href="https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy/src/branch/master/LICENSE">LICENSE</a> for more information.
 | 
			
		||||
Distributed under the AGPL-3.0 License. See <a href="https://codeberg.org/Bazsalanszky/Eternity/src/branch/master/LICENSE">LICENSE</a> for more information.
 | 
			
		||||
 | 
			
		||||
<p align="right">(<a href="#top">back to top</a>)</p>
 | 
			
		||||
 | 
			
		||||
@@ -86,6 +92,6 @@ Distributed under the AGPL-3.0 License. See <a href="https://codeberg.org/Bazsal
 | 
			
		||||
 | 
			
		||||
[@bazsalanszky@lemmy.toldi.eu](https://lemmy.toldi.eu/u/bazsalanszky) - (Owner)
 | 
			
		||||
 | 
			
		||||
Project Link: [https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy](https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy)
 | 
			
		||||
Project Link: [https://codeberg.org/Bazsalanszky/Eternity](https://codeberg.org/Bazsalanszky/Eternity)
 | 
			
		||||
 | 
			
		||||
<p align="right">(<a href="#top">back to top</a>)</p>
 | 
			
		||||
 
 | 
			
		||||
@@ -98,6 +98,30 @@ android {
 | 
			
		||||
        doNotStrip '**/*.so'
 | 
			
		||||
    }
 | 
			
		||||
    namespace 'eu.toldi.infinityforlemmy'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    task rearrangeClass(type: Exec) {
 | 
			
		||||
        commandLine 'python', '../scripts/fixEventBus.py'
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    applicationVariants.all { variant ->
 | 
			
		||||
        if (variant.name == 'release') {
 | 
			
		||||
            task("compileSingleFile${variant.name.capitalize()}", type: JavaCompile, dependsOn: rearrangeClass) {
 | 
			
		||||
                def filePath = project.rootDir.absolutePath + '/app/build/generated/ap_generated_sources/release/out/eu/toldi/infinityforlemmy/'
 | 
			
		||||
                source = files(filePath)
 | 
			
		||||
                includes = ["**/EventBusIndex.java"]
 | 
			
		||||
                classpath = variant.getCompileClasspath() + files(project.rootDir.absolutePath + '/app/build/intermediates/javac/release/classes')
 | 
			
		||||
                destinationDir = file("$buildDir/intermediates/javac/release/classes")
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            tasks.withType(JavaCompile).all { task ->
 | 
			
		||||
                if (task.name == 'compileReleaseJavaWithJavac') {
 | 
			
		||||
                    task.finalizedBy "compileSingleFile${variant.name.capitalize()}"
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
dependencies {
 | 
			
		||||
@@ -196,6 +220,7 @@ dependencies {
 | 
			
		||||
    def glideVersion = "4.12.0"
 | 
			
		||||
    implementation "com.github.bumptech.glide:glide:$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 'com.github.santalu:aspect-ratio-imageview:1.0.9'
 | 
			
		||||
    implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.23'
 | 
			
		||||
@@ -245,3 +270,34 @@ dependencies {
 | 
			
		||||
    //debugImplementation 'com.squareup.leakcanary:leakcanary-android:x.y'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NB: Android Studio can't find the imports; this does not affect the
 | 
			
		||||
// actual build since Gradle can find them just fine.
 | 
			
		||||
 | 
			
		||||
import com.android.tools.profgen.ArtProfileKt
 | 
			
		||||
import com.android.tools.profgen.ArtProfileSerializer
 | 
			
		||||
import com.android.tools.profgen.DexFile
 | 
			
		||||
 | 
			
		||||
project.afterEvaluate {
 | 
			
		||||
    tasks.each { task ->
 | 
			
		||||
        if (task.name.startsWith("compile") && task.name.endsWith("ReleaseArtProfile")) {
 | 
			
		||||
            task.doLast {
 | 
			
		||||
                outputs.files.each { file ->
 | 
			
		||||
                    if (file.name.endsWith(".profm")) {
 | 
			
		||||
                        println("Sorting ${file} ...")
 | 
			
		||||
                        def version = ArtProfileSerializer.valueOf("METADATA_0_0_2")
 | 
			
		||||
                        def profile = ArtProfileKt.ArtProfile(file)
 | 
			
		||||
                        def keys = new ArrayList(profile.profileData.keySet())
 | 
			
		||||
                        def sortedData = new LinkedHashMap()
 | 
			
		||||
                        Collections.sort keys, new DexFile.Companion()
 | 
			
		||||
                        keys.each { key -> sortedData[key] = profile.profileData[key] }
 | 
			
		||||
                        new FileOutputStream(file).with {
 | 
			
		||||
                            write(version.magicBytes$profgen)
 | 
			
		||||
                            write(version.versionBytes$profgen)
 | 
			
		||||
                            version.write$profgen(it, sortedData, "")
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -113,7 +113,7 @@ import eu.toldi.infinityforlemmy.settings.TranslationFragment;
 | 
			
		||||
import eu.toldi.infinityforlemmy.settings.VideoPreferenceFragment;
 | 
			
		||||
 | 
			
		||||
@Singleton
 | 
			
		||||
@Component(modules = {AppModule.class, NetworkModule.class})
 | 
			
		||||
@Component(modules = {AppModule.class, NetworkModule.class, PostEnricherModule.class})
 | 
			
		||||
public interface AppComponent {
 | 
			
		||||
    void inject(MainActivity mainActivity);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,5 @@
 | 
			
		||||
package eu.toldi.infinityforlemmy;
 | 
			
		||||
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
import android.content.SharedPreferences;
 | 
			
		||||
import android.os.Handler;
 | 
			
		||||
 | 
			
		||||
import org.json.JSONException;
 | 
			
		||||
@@ -12,9 +10,7 @@ import java.util.concurrent.Executor;
 | 
			
		||||
 | 
			
		||||
import eu.toldi.infinityforlemmy.apis.GfycatAPI;
 | 
			
		||||
import eu.toldi.infinityforlemmy.apis.RedgifsAPI;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.JSONUtils;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
 | 
			
		||||
import retrofit2.Call;
 | 
			
		||||
import retrofit2.Response;
 | 
			
		||||
import retrofit2.Retrofit;
 | 
			
		||||
@@ -44,14 +40,12 @@ public class FetchGfycatOrRedgifsVideoLinks {
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void fetchRedgifsVideoLinks(Context context, Executor executor, Handler handler, Retrofit redgifsRetrofit,
 | 
			
		||||
                                              SharedPreferences currentAccountSharedPreferences,
 | 
			
		||||
    public static void fetchRedgifsVideoLinks(Executor executor, Handler handler, Retrofit redgifsRetrofit,
 | 
			
		||||
                                              String gfycatId,
 | 
			
		||||
                                              FetchGfycatOrRedgifsVideoLinksListener fetchGfycatOrRedgifsVideoLinksListener) {
 | 
			
		||||
        executor.execute(() -> {
 | 
			
		||||
            try {
 | 
			
		||||
                Response<String> response = redgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(APIUtils.getRedgifsOAuthHeader(currentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "")),
 | 
			
		||||
                         gfycatId, APIUtils.USER_AGENT).execute();
 | 
			
		||||
                Response<String> response = redgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(gfycatId).execute();
 | 
			
		||||
                if (response.isSuccessful()) {
 | 
			
		||||
                    parseRedgifsVideoLinks(handler, response.body(), fetchGfycatOrRedgifsVideoLinksListener);
 | 
			
		||||
                } else {
 | 
			
		||||
 
 | 
			
		||||
@@ -11,6 +11,16 @@ import android.os.Bundle;
 | 
			
		||||
import android.view.WindowManager;
 | 
			
		||||
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.livefront.bridge.Bridge;
 | 
			
		||||
import com.livefront.bridge.SavedStateHandler;
 | 
			
		||||
@@ -18,15 +28,11 @@ import com.livefront.bridge.SavedStateHandler;
 | 
			
		||||
import org.greenrobot.eventbus.EventBus;
 | 
			
		||||
import org.greenrobot.eventbus.Subscribe;
 | 
			
		||||
 | 
			
		||||
import java.io.InputStream;
 | 
			
		||||
 | 
			
		||||
import javax.inject.Inject;
 | 
			
		||||
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.broadcastreceivers.NetworkWifiStatusReceiver;
 | 
			
		||||
import eu.toldi.infinityforlemmy.broadcastreceivers.WallpaperChangeReceiver;
 | 
			
		||||
@@ -38,6 +44,8 @@ import eu.toldi.infinityforlemmy.font.FontFamily;
 | 
			
		||||
import eu.toldi.infinityforlemmy.font.TitleFontFamily;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.Utils;
 | 
			
		||||
import okhttp3.Call;
 | 
			
		||||
import okhttp3.OkHttpClient;
 | 
			
		||||
 | 
			
		||||
public class Infinity extends Application implements LifecycleObserver {
 | 
			
		||||
    public Typeface typeface;
 | 
			
		||||
@@ -55,6 +63,9 @@ public class Infinity extends Application implements LifecycleObserver {
 | 
			
		||||
    @Inject
 | 
			
		||||
    @Named("security")
 | 
			
		||||
    SharedPreferences mSecuritySharedPreferences;
 | 
			
		||||
    @Inject
 | 
			
		||||
    @Named("glide")
 | 
			
		||||
    OkHttpClient glideOkHttpClient;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onCreate() {
 | 
			
		||||
@@ -159,6 +170,9 @@ public class Infinity extends Application implements LifecycleObserver {
 | 
			
		||||
        registerReceiver(mNetworkWifiStatusReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
 | 
			
		||||
 | 
			
		||||
        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)
 | 
			
		||||
 
 | 
			
		||||
@@ -9,10 +9,11 @@ import javax.inject.Singleton;
 | 
			
		||||
 | 
			
		||||
import dagger.Module;
 | 
			
		||||
import dagger.Provides;
 | 
			
		||||
import eu.toldi.infinityforlemmy.apis.RedgifsAPI;
 | 
			
		||||
import eu.toldi.infinityforlemmy.apis.StreamableAPI;
 | 
			
		||||
import eu.toldi.infinityforlemmy.privatemessage.LemmyPrivateMessageAPI;
 | 
			
		||||
import eu.toldi.infinityforlemmy.comment.LemmyCommentAPI;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.LemmyPostAPI;
 | 
			
		||||
import eu.toldi.infinityforlemmy.privatemessage.LemmyPrivateMessageAPI;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
 | 
			
		||||
import okhttp3.ConnectionPool;
 | 
			
		||||
import okhttp3.Interceptor;
 | 
			
		||||
@@ -34,6 +35,21 @@ abstract class NetworkModule {
 | 
			
		||||
                .build();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Provides
 | 
			
		||||
    @Named("glide")
 | 
			
		||||
    @Singleton
 | 
			
		||||
    static OkHttpClient provideGlideOkHttp(@Named("base") OkHttpClient baseOkHttp,
 | 
			
		||||
                                           @Named("RedgifsAccessTokenAuthenticator") Interceptor redGifsAuthenticator) {
 | 
			
		||||
        return baseOkHttp.newBuilder()
 | 
			
		||||
                .addInterceptor(chain -> chain.proceed(
 | 
			
		||||
                        chain.request()
 | 
			
		||||
                                .newBuilder()
 | 
			
		||||
                                .header("User-Agent", APIUtils.USER_AGENT)
 | 
			
		||||
                                .build()
 | 
			
		||||
                ))
 | 
			
		||||
                .addInterceptor(redGifsAuthenticator)
 | 
			
		||||
                .build();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Provides
 | 
			
		||||
    @Named("base")
 | 
			
		||||
@@ -165,6 +181,12 @@ abstract class NetworkModule {
 | 
			
		||||
                .build();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Provides
 | 
			
		||||
    @Singleton
 | 
			
		||||
    static RedgifsAPI provideRedgifsAPI(@Named("redgifs") Retrofit redgifsRetrofit) {
 | 
			
		||||
        return redgifsRetrofit.create(RedgifsAPI.class);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Provides
 | 
			
		||||
    @Named("imgur")
 | 
			
		||||
    @Singleton
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,26 @@
 | 
			
		||||
package eu.toldi.infinityforlemmy;
 | 
			
		||||
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
 | 
			
		||||
import dagger.Module;
 | 
			
		||||
import dagger.Provides;
 | 
			
		||||
import dagger.multibindings.IntoSet;
 | 
			
		||||
import eu.toldi.infinityforlemmy.apis.RedgifsAPI;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.enrich.CompositePostEnricher;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.enrich.RedGifsPostEnricher;
 | 
			
		||||
 | 
			
		||||
@Module
 | 
			
		||||
abstract class PostEnricherModule {
 | 
			
		||||
 | 
			
		||||
    @Provides
 | 
			
		||||
    @IntoSet
 | 
			
		||||
    static PostEnricher provideRedGifsPostEnricher(RedgifsAPI redgifsAPI) {
 | 
			
		||||
        return new RedGifsPostEnricher(redgifsAPI);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Provides
 | 
			
		||||
    static PostEnricher providePostEnricher(Set<PostEnricher> postEnrichers) {
 | 
			
		||||
        return new CompositePostEnricher(postEnrichers);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -14,7 +14,6 @@ import java.util.Map;
 | 
			
		||||
import eu.toldi.infinityforlemmy.apis.RedgifsAPI;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
 | 
			
		||||
import okhttp3.Headers;
 | 
			
		||||
import okhttp3.Interceptor;
 | 
			
		||||
import okhttp3.Response;
 | 
			
		||||
import retrofit2.Call;
 | 
			
		||||
@@ -22,6 +21,8 @@ import retrofit2.Retrofit;
 | 
			
		||||
import retrofit2.converter.scalars.ScalarsConverterFactory;
 | 
			
		||||
 | 
			
		||||
public class RedgifsAccessTokenAuthenticator implements Interceptor {
 | 
			
		||||
    private static final String REDGIFS_HOST = "redgifs.com";
 | 
			
		||||
 | 
			
		||||
    private SharedPreferences mCurrentAccountSharedPreferences;
 | 
			
		||||
 | 
			
		||||
    public RedgifsAccessTokenAuthenticator(SharedPreferences currentAccountSharedPreferences) {
 | 
			
		||||
@@ -60,7 +61,17 @@ public class RedgifsAccessTokenAuthenticator implements Interceptor {
 | 
			
		||||
    @NonNull
 | 
			
		||||
    @Override
 | 
			
		||||
    public Response intercept(@NonNull Chain chain) throws IOException {
 | 
			
		||||
        Response response = chain.proceed(chain.request());
 | 
			
		||||
        if (!chain.request().url().host().endsWith(REDGIFS_HOST)) {
 | 
			
		||||
            return chain.proceed(chain.request());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        String currentAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "");
 | 
			
		||||
        Response response = chain.proceed(
 | 
			
		||||
                chain.request().newBuilder()
 | 
			
		||||
                        .addHeader(APIUtils.AUTHORIZATION_KEY, APIUtils.AUTHORIZATION_BASE + currentAccessToken)
 | 
			
		||||
                        .build()
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        if (response.code() == 401 || response.code() == 400) {
 | 
			
		||||
            String accessTokenHeader = response.request().header(APIUtils.AUTHORIZATION_KEY);
 | 
			
		||||
            if (accessTokenHeader == null) {
 | 
			
		||||
@@ -74,13 +85,21 @@ public class RedgifsAccessTokenAuthenticator implements Interceptor {
 | 
			
		||||
                    String newAccessToken = refreshAccessToken();
 | 
			
		||||
                    if (!newAccessToken.equals("")) {
 | 
			
		||||
                        response.close();
 | 
			
		||||
                        return chain.proceed(response.request().newBuilder().headers(Headers.of(APIUtils.getRedgifsOAuthHeader(newAccessToken))).build());
 | 
			
		||||
                        return chain.proceed(
 | 
			
		||||
                                chain.request().newBuilder()
 | 
			
		||||
                                        .addHeader(APIUtils.AUTHORIZATION_KEY, APIUtils.AUTHORIZATION_BASE + newAccessToken)
 | 
			
		||||
                                        .build()
 | 
			
		||||
                        );
 | 
			
		||||
                    } else {
 | 
			
		||||
                        return response;
 | 
			
		||||
                    }
 | 
			
		||||
                } else {
 | 
			
		||||
                    response.close();
 | 
			
		||||
                    return chain.proceed(response.request().newBuilder().headers(Headers.of(APIUtils.getRedgifsOAuthHeader(accessTokenFromSharedPreferences))).build());
 | 
			
		||||
                    return chain.proceed(
 | 
			
		||||
                            chain.request().newBuilder()
 | 
			
		||||
                                    .addHeader(APIUtils.AUTHORIZATION_KEY, APIUtils.AUTHORIZATION_BASE + accessTokenFromSharedPreferences)
 | 
			
		||||
                                    .build()
 | 
			
		||||
                    );
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,10 @@
 | 
			
		||||
package eu.toldi.infinityforlemmy;
 | 
			
		||||
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
 | 
			
		||||
import eu.toldi.infinityforlemmy.network.SortTypeConverterFactory;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
 | 
			
		||||
import okhttp3.Interceptor;
 | 
			
		||||
import okhttp3.OkHttpClient;
 | 
			
		||||
import retrofit2.Retrofit;
 | 
			
		||||
import retrofit2.adapter.guava.GuavaCallAdapterFactory;
 | 
			
		||||
@@ -12,8 +15,14 @@ public class RetrofitHolder {
 | 
			
		||||
 | 
			
		||||
    private Retrofit retrofit;
 | 
			
		||||
    private OkHttpClient okHttpClient;
 | 
			
		||||
 | 
			
		||||
    private OkHttpClient okHttpClientBase;
 | 
			
		||||
    private String baseURL = APIUtils.API_BASE_URI;
 | 
			
		||||
 | 
			
		||||
    private String accessToken = null;
 | 
			
		||||
 | 
			
		||||
    private Interceptor oAuthInterceptor;
 | 
			
		||||
 | 
			
		||||
    public Retrofit getRetrofit() {
 | 
			
		||||
        return retrofit;
 | 
			
		||||
    }
 | 
			
		||||
@@ -33,6 +42,7 @@ public class RetrofitHolder {
 | 
			
		||||
 | 
			
		||||
    public RetrofitHolder(OkHttpClient okHttpClient) {
 | 
			
		||||
        this.okHttpClient = okHttpClient;
 | 
			
		||||
        this.okHttpClientBase = okHttpClient;
 | 
			
		||||
        this.retrofit = createRetrofit(okHttpClient, APIUtils.API_BASE_URI);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -46,4 +56,18 @@ public class RetrofitHolder {
 | 
			
		||||
                .addConverterFactory(GsonConverterFactory.create())
 | 
			
		||||
                .build();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setAccessToken(String accessToken) {
 | 
			
		||||
        this.accessToken = accessToken;
 | 
			
		||||
        OkHttpClient.Builder builder = okHttpClientBase.newBuilder();
 | 
			
		||||
        Log.d("RetrofitHolder", "Access token changed");
 | 
			
		||||
        if (accessToken != null && !accessToken.equals("")) {
 | 
			
		||||
            Log.i("RetrofitHolder", "Setting access token interceptor");
 | 
			
		||||
            oAuthInterceptor = APIUtils.getOAuthInterceptor(accessToken);
 | 
			
		||||
            builder.addInterceptor(oAuthInterceptor);
 | 
			
		||||
        }
 | 
			
		||||
        okHttpClient = builder.build();
 | 
			
		||||
        retrofit = createRetrofit(okHttpClient, baseURL);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -69,15 +69,15 @@ public class SortType {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public enum Time {
 | 
			
		||||
        HOUR("TopHour", "Top Hour"),
 | 
			
		||||
        SIX_HOURS("TopSixHour", "Top Six Hours"),
 | 
			
		||||
        TWELVE_HOURS("TopTwelveHour", "Top Twelve Hours"),
 | 
			
		||||
        HOUR("hour", "Hour"),
 | 
			
		||||
        SIX_HOURS("SixHour", "Six Hours"),
 | 
			
		||||
        TWELVE_HOURS("TwelveHour", "Twelve Hours"),
 | 
			
		||||
        DAY("day", "Day"),
 | 
			
		||||
        WEEK("week", "Week"),
 | 
			
		||||
        MONTH("month", "Month"),
 | 
			
		||||
        THREE_MONTHS("TopThreeMonth", "Top Three Months"),
 | 
			
		||||
        SIX_MONTHS("TopSixMonth", "Top Six Months"),
 | 
			
		||||
        NINE_MONTHS("TopNineMonth", "Top Nine Months"),
 | 
			
		||||
        THREE_MONTHS("ThreeMonths", "Three Months"),
 | 
			
		||||
        SIX_MONTHS("SixMonths", "Six Months"),
 | 
			
		||||
        NINE_MONTHS("NineMonths", "Nine Months"),
 | 
			
		||||
        YEAR("year", "Year"),
 | 
			
		||||
        ALL("all", "All Time");
 | 
			
		||||
 | 
			
		||||
@@ -88,5 +88,14 @@ public class SortType {
 | 
			
		||||
            this.value = value;
 | 
			
		||||
            this.fullName = fullName;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static Time fromValue(String value) {
 | 
			
		||||
            for (Time time : values()) {
 | 
			
		||||
                if (time.value.equalsIgnoreCase(value)) {
 | 
			
		||||
                    return time;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -283,7 +283,7 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
 | 
			
		||||
                PostFragment fragment = new PostFragment();
 | 
			
		||||
                Bundle bundle = new Bundle();
 | 
			
		||||
                bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_USER);
 | 
			
		||||
                bundle.putString(PostFragment.EXTRA_USER_NAME, mAccountName);
 | 
			
		||||
                bundle.putString(PostFragment.EXTRA_USER_NAME, mAccountQualifiedName);
 | 
			
		||||
                bundle.putString(PostFragment.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_SAVED);
 | 
			
		||||
                bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
 | 
			
		||||
                bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
 | 
			
		||||
@@ -293,7 +293,7 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
 | 
			
		||||
            }
 | 
			
		||||
            CommentsListingFragment fragment = new CommentsListingFragment();
 | 
			
		||||
            Bundle bundle = new Bundle();
 | 
			
		||||
            bundle.putString(CommentsListingFragment.EXTRA_USERNAME, mAccountName);
 | 
			
		||||
            bundle.putString(CommentsListingFragment.EXTRA_USERNAME, mAccountQualifiedName);
 | 
			
		||||
            bundle.putString(CommentsListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
 | 
			
		||||
            bundle.putString(CommentsListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
 | 
			
		||||
            bundle.putBoolean(CommentsListingFragment.EXTRA_ARE_SAVED_COMMENTS, true);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,14 +1,19 @@
 | 
			
		||||
package eu.toldi.infinityforlemmy.activities;
 | 
			
		||||
 | 
			
		||||
import android.content.Intent;
 | 
			
		||||
import android.content.SharedPreferences;
 | 
			
		||||
import android.graphics.Color;
 | 
			
		||||
import android.graphics.PorterDuff;
 | 
			
		||||
import android.net.Uri;
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
import android.text.Spanned;
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import android.view.MenuItem;
 | 
			
		||||
import android.view.View;
 | 
			
		||||
import android.widget.ImageView;
 | 
			
		||||
import android.widget.TextView;
 | 
			
		||||
 | 
			
		||||
import androidx.annotation.NonNull;
 | 
			
		||||
import androidx.annotation.Nullable;
 | 
			
		||||
import androidx.appcompat.widget.Toolbar;
 | 
			
		||||
import androidx.constraintlayout.widget.ConstraintLayout;
 | 
			
		||||
@@ -40,6 +45,9 @@ import eu.toldi.infinityforlemmy.user.BasicUserInfo;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
 | 
			
		||||
import io.noties.markwon.AbstractMarkwonPlugin;
 | 
			
		||||
import io.noties.markwon.Markwon;
 | 
			
		||||
import io.noties.markwon.MarkwonConfiguration;
 | 
			
		||||
import io.noties.markwon.MarkwonPlugin;
 | 
			
		||||
import io.noties.markwon.core.MarkwonTheme;
 | 
			
		||||
import io.noties.markwon.recycler.MarkwonAdapter;
 | 
			
		||||
 | 
			
		||||
public class InstanceInfoActivity extends BaseActivity {
 | 
			
		||||
@@ -105,16 +113,43 @@ public class InstanceInfoActivity extends BaseActivity {
 | 
			
		||||
 | 
			
		||||
        setSupportActionBar(toolbar);
 | 
			
		||||
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        // Remove transparency from navigation bar
 | 
			
		||||
        getWindow().setNavigationBarColor(mCustomThemeWrapper.getBackgroundColor());
 | 
			
		||||
 | 
			
		||||
        int markdownColor = customThemeWrapper.getPostContentColor();
 | 
			
		||||
        int postSpoilerBackgroundColor = markdownColor | 0xFF000000;
 | 
			
		||||
        int linkColor = customThemeWrapper.getLinkColor();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        MarkwonPlugin miscPlugin = new AbstractMarkwonPlugin() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) {
 | 
			
		||||
                if (InstanceInfoActivity.this.contentTypeface != null) {
 | 
			
		||||
                    textView.setTypeface(InstanceInfoActivity.this.contentTypeface);
 | 
			
		||||
                }
 | 
			
		||||
                textView.setTextColor(markdownColor);
 | 
			
		||||
                textView.setHighlightColor(Color.TRANSPARENT);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) {
 | 
			
		||||
                builder.linkResolver((view, link) -> {
 | 
			
		||||
                    Intent intent = new Intent(InstanceInfoActivity.this, LinkResolverActivity.class);
 | 
			
		||||
                    Uri uri = Uri.parse(link);
 | 
			
		||||
                    intent.setData(uri);
 | 
			
		||||
                    InstanceInfoActivity.this.startActivity(intent);
 | 
			
		||||
                });
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            @Override
 | 
			
		||||
            public void configureTheme(@NonNull MarkwonTheme.Builder builder) {
 | 
			
		||||
                builder.linkColor(linkColor);
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        mPostDetailMarkwon = MarkdownUtils.createFullRedditMarkwon(this,
 | 
			
		||||
                new AbstractMarkwonPlugin() {
 | 
			
		||||
                }, markdownColor, postSpoilerBackgroundColor, null);
 | 
			
		||||
                miscPlugin, markdownColor, postSpoilerBackgroundColor, null);
 | 
			
		||||
        mMarkwonAdapter = MarkdownUtils.createTablesAdapter();
 | 
			
		||||
        mContentMarkdownView.setAdapter(mMarkwonAdapter);
 | 
			
		||||
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
 | 
			
		||||
 
 | 
			
		||||
@@ -36,6 +36,7 @@ import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.FetchPost;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.ObjectResolver;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.Post;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
 | 
			
		||||
 | 
			
		||||
@@ -83,6 +84,9 @@ public class LinkResolverActivity extends AppCompatActivity {
 | 
			
		||||
    @Inject
 | 
			
		||||
    Executor mExecutor;
 | 
			
		||||
 | 
			
		||||
    @Inject
 | 
			
		||||
    PostEnricher postEnricher;
 | 
			
		||||
 | 
			
		||||
    private String mAccessToken;
 | 
			
		||||
 | 
			
		||||
    private Uri getRedditUriByPath(String path) {
 | 
			
		||||
@@ -102,6 +106,9 @@ public class LinkResolverActivity extends AppCompatActivity {
 | 
			
		||||
        if (mAccessToken != null) {
 | 
			
		||||
            String instance = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_INSTANCE, null);
 | 
			
		||||
            mRetrofit.setBaseURL(instance);
 | 
			
		||||
            if (mCurrentAccountSharedPreferences.getBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, true)) {
 | 
			
		||||
                mRetrofit.setAccessToken(mAccessToken);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Uri uri = getIntent().getData();
 | 
			
		||||
@@ -214,7 +221,7 @@ public class LinkResolverActivity extends AppCompatActivity {
 | 
			
		||||
                                    URL baseURL = new URL(mRetrofit.getBaseURL());
 | 
			
		||||
                                    if (baseURL.getHost().equalsIgnoreCase(uri.getHost())) {
 | 
			
		||||
                                        local = true;
 | 
			
		||||
                                        FetchPost.fetchPost(mExecutor, new Handler(), mRetrofit.getRetrofit(), segments.get(segments.size() - 1), mAccessToken, new FetchPost.FetchPostListener() {
 | 
			
		||||
                                        FetchPost.fetchPost(mExecutor, new Handler(), mRetrofit.getRetrofit(), segments.get(segments.size() - 1), mAccessToken, postEnricher, new FetchPost.FetchPostListener() {
 | 
			
		||||
                                            @Override
 | 
			
		||||
                                            public void fetchPostSuccess(Post post) {
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,6 @@ import android.os.Bundle;
 | 
			
		||||
import android.os.Handler;
 | 
			
		||||
import android.text.Editable;
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import android.util.Patterns;
 | 
			
		||||
import android.view.InflateException;
 | 
			
		||||
import android.view.MenuItem;
 | 
			
		||||
import android.widget.Button;
 | 
			
		||||
@@ -180,6 +179,7 @@ public class LoginActivity extends BaseActivity {
 | 
			
		||||
                        try {
 | 
			
		||||
                            JSONObject responseJSON = new JSONObject(accountResponse);
 | 
			
		||||
                            String accessToken = responseJSON.getString("jwt");
 | 
			
		||||
                            mRetrofit.setAccessToken(null);
 | 
			
		||||
 | 
			
		||||
                            FetchMyInfo.fetchAccountInfo(mRetrofit.getRetrofit(), mRedditDataRoomDatabase, username,
 | 
			
		||||
                                    accessToken, new FetchMyInfo.FetchMyInfoListener() {
 | 
			
		||||
@@ -189,13 +189,23 @@ public class LoginActivity extends BaseActivity {
 | 
			
		||||
                                                @Override
 | 
			
		||||
                                                public void onFetchSiteInfoSuccess(SiteInfo siteInfo) {
 | 
			
		||||
                                                    boolean canDownvote = siteInfo.isEnable_downvotes();
 | 
			
		||||
                                                    ParseAndInsertNewAccount.parseAndInsertNewAccount(mExecutor, new Handler(), name,display_name, accessToken,  profileImageUrl, bannerImageUrl, authCode, finalInstance,canDownvote, mRedditDataRoomDatabase.accountDao(),
 | 
			
		||||
                                                    ParseAndInsertNewAccount.parseAndInsertNewAccount(mExecutor, new Handler(), name, display_name, accessToken, profileImageUrl, bannerImageUrl, authCode, finalInstance, canDownvote, mRedditDataRoomDatabase.accountDao(),
 | 
			
		||||
                                                            () -> {
 | 
			
		||||
                                                                Intent resultIntent = new Intent();
 | 
			
		||||
                                                                setResult(Activity.RESULT_OK, resultIntent);
 | 
			
		||||
                                                                finish();
 | 
			
		||||
                                                            });
 | 
			
		||||
                                                    mCurrentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.CAN_DOWNVOTE, canDownvote).apply();
 | 
			
		||||
                                                    String[] version = siteInfo.getVersion().split("\\.");
 | 
			
		||||
                                                    if (version.length > 0) {
 | 
			
		||||
                                                        Log.d("SwitchAccount", "Lemmy Version: " + version[0] + "." + version[1]);
 | 
			
		||||
                                                        int majorVersion = Integer.parseInt(version[0]);
 | 
			
		||||
                                                        int minorVersion = Integer.parseInt(version[1]);
 | 
			
		||||
                                                        if (majorVersion > 0 || (majorVersion == 0 && minorVersion >= 19)) {
 | 
			
		||||
                                                            mRetrofit.setAccessToken(accessToken);
 | 
			
		||||
                                                            mCurrentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, true).apply();
 | 
			
		||||
                                                        }
 | 
			
		||||
                                                    }
 | 
			
		||||
                                                }
 | 
			
		||||
 | 
			
		||||
                                                @Override
 | 
			
		||||
 
 | 
			
		||||
@@ -336,11 +336,14 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
 | 
			
		||||
        fragmentManager = getSupportFragmentManager();
 | 
			
		||||
 | 
			
		||||
        mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
 | 
			
		||||
        if (mCurrentAccountSharedPreferences.getBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, true)) {
 | 
			
		||||
            mRetrofit.setAccessToken(mAccessToken);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
 | 
			
		||||
        mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
 | 
			
		||||
        String instance = (mAccessToken == null) ? mSharedPreferences.getString(SharedPreferencesUtils.ANONYMOUS_ACCOUNT_INSTANCE, APIUtils.API_BASE_URI) : mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_INSTANCE, null);
 | 
			
		||||
        if(instance != null) {
 | 
			
		||||
        if (instance != null) {
 | 
			
		||||
            mRetrofit.setBaseURL(instance);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -365,7 +368,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
 | 
			
		||||
        super.onResume();
 | 
			
		||||
        if (mAccessToken == null) {
 | 
			
		||||
            String instancePreference = mSharedPreferences.getString(SharedPreferencesUtils.ANONYMOUS_ACCOUNT_INSTANCE, APIUtils.API_BASE_URI);
 | 
			
		||||
            if (!mRetrofit.getBaseURL().equalsIgnoreCase(instancePreference)) {
 | 
			
		||||
            if (!instancePreference.startsWith(mRetrofit.getBaseURL())) {
 | 
			
		||||
                mRetrofit.setBaseURL(instancePreference);
 | 
			
		||||
                this.recreate();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@@ -1510,7 +1514,12 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
 | 
			
		||||
            if (i == EditorInfo.IME_ACTION_DONE) {
 | 
			
		||||
                Utils.hideKeyboard(this);
 | 
			
		||||
                Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
 | 
			
		||||
                subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, thingEditText.getText().toString());
 | 
			
		||||
                String communityName = thingEditText.getText().toString();
 | 
			
		||||
                if (communityName.startsWith("!")) {
 | 
			
		||||
                    communityName = communityName.substring(1);
 | 
			
		||||
                }
 | 
			
		||||
                subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName);
 | 
			
		||||
 | 
			
		||||
                startActivity(subredditIntent);
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
@@ -1568,7 +1577,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
 | 
			
		||||
                        -> {
 | 
			
		||||
                    Utils.hideKeyboard(this);
 | 
			
		||||
                    Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
 | 
			
		||||
                    subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, thingEditText.getText().toString());
 | 
			
		||||
                    String communityName = thingEditText.getText().toString();
 | 
			
		||||
                    if (communityName.startsWith("!")) {
 | 
			
		||||
                        communityName = communityName.substring(1);
 | 
			
		||||
                    }
 | 
			
		||||
                    subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName);
 | 
			
		||||
                    startActivity(subredditIntent);
 | 
			
		||||
                })
 | 
			
		||||
                .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
 | 
			
		||||
@@ -1589,7 +1602,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
 | 
			
		||||
            if (i == EditorInfo.IME_ACTION_DONE) {
 | 
			
		||||
                Utils.hideKeyboard(this);
 | 
			
		||||
                Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
 | 
			
		||||
                userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, thingEditText.getText().toString());
 | 
			
		||||
                String qualifiedName = thingEditText.getText().toString();
 | 
			
		||||
                if (qualifiedName.startsWith("@")) {
 | 
			
		||||
                    qualifiedName = qualifiedName.substring(1);
 | 
			
		||||
                }
 | 
			
		||||
                userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, qualifiedName);
 | 
			
		||||
                startActivity(userIntent);
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
@@ -1602,7 +1619,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
 | 
			
		||||
                        -> {
 | 
			
		||||
                    Utils.hideKeyboard(this);
 | 
			
		||||
                    Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
 | 
			
		||||
                    userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, thingEditText.getText().toString());
 | 
			
		||||
                    String qualifiedName = thingEditText.getText().toString();
 | 
			
		||||
                    if (qualifiedName.startsWith("@")) {
 | 
			
		||||
                        qualifiedName = qualifiedName.substring(1);
 | 
			
		||||
                    }
 | 
			
		||||
                    userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, qualifiedName);
 | 
			
		||||
                    startActivity(userIntent);
 | 
			
		||||
                })
 | 
			
		||||
                .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
 | 
			
		||||
 
 | 
			
		||||
@@ -78,6 +78,7 @@ import eu.toldi.infinityforlemmy.font.TitleFontStyle;
 | 
			
		||||
import eu.toldi.infinityforlemmy.services.DownloadMediaService;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.Utils;
 | 
			
		||||
import okhttp3.OkHttpClient;
 | 
			
		||||
 | 
			
		||||
public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWallpaperCallback, CustomFontReceiver {
 | 
			
		||||
 | 
			
		||||
@@ -108,6 +109,9 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
 | 
			
		||||
    @Named("default")
 | 
			
		||||
    SharedPreferences mSharedPreferences;
 | 
			
		||||
    @Inject
 | 
			
		||||
    @Named("glide")
 | 
			
		||||
    OkHttpClient okHttpClient;
 | 
			
		||||
    @Inject
 | 
			
		||||
    Executor mExecutor;
 | 
			
		||||
    private boolean isActionBarHidden = false;
 | 
			
		||||
    private boolean isDownloading = false;
 | 
			
		||||
@@ -146,7 +150,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
 | 
			
		||||
        getTheme().applyStyle(ContentFontFamily.valueOf(mSharedPreferences
 | 
			
		||||
                .getString(SharedPreferencesUtils.CONTENT_FONT_FAMILY_KEY, ContentFontFamily.Default.name())).getResId(), true);
 | 
			
		||||
 | 
			
		||||
        BigImageViewer.initialize(GlideImageLoader.with(this.getApplicationContext()));
 | 
			
		||||
        BigImageViewer.initialize(GlideImageLoader.with(this.getApplicationContext(), okHttpClient));
 | 
			
		||||
 | 
			
		||||
        setContentView(R.layout.activity_view_image_or_gif);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -67,6 +67,7 @@ import eu.toldi.infinityforlemmy.SaveComment;
 | 
			
		||||
import eu.toldi.infinityforlemmy.SaveThing;
 | 
			
		||||
import eu.toldi.infinityforlemmy.SortType;
 | 
			
		||||
import eu.toldi.infinityforlemmy.SortTypeSelectionCallback;
 | 
			
		||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
 | 
			
		||||
import eu.toldi.infinityforlemmy.apis.RedditAPI;
 | 
			
		||||
import eu.toldi.infinityforlemmy.asynctasks.SwitchAccount;
 | 
			
		||||
import eu.toldi.infinityforlemmy.comment.Comment;
 | 
			
		||||
@@ -81,10 +82,12 @@ import eu.toldi.infinityforlemmy.post.HistoryPostPagingSource;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.ParsePost;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.Post;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.PostPagingSource;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
 | 
			
		||||
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
 | 
			
		||||
import eu.toldi.infinityforlemmy.readpost.ReadPost;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
 | 
			
		||||
import okhttp3.OkHttpClient;
 | 
			
		||||
import retrofit2.Call;
 | 
			
		||||
import retrofit2.Response;
 | 
			
		||||
import retrofit2.Retrofit;
 | 
			
		||||
@@ -147,6 +150,11 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
 | 
			
		||||
    CustomThemeWrapper mCustomThemeWrapper;
 | 
			
		||||
    @Inject
 | 
			
		||||
    Executor mExecutor;
 | 
			
		||||
    @Inject
 | 
			
		||||
    @Named("glide")
 | 
			
		||||
    OkHttpClient okHttpClient;
 | 
			
		||||
    @Inject
 | 
			
		||||
    PostEnricher postEnricher;
 | 
			
		||||
    @State
 | 
			
		||||
    ArrayList<Post> posts;
 | 
			
		||||
    @State
 | 
			
		||||
@@ -195,7 +203,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
 | 
			
		||||
 | 
			
		||||
        super.onCreate(savedInstanceState);
 | 
			
		||||
 | 
			
		||||
        BigImageViewer.initialize(GlideImageLoader.with(this.getApplicationContext()));
 | 
			
		||||
        BigImageViewer.initialize(GlideImageLoader.with(this.getApplicationContext(), okHttpClient));
 | 
			
		||||
 | 
			
		||||
        setContentView(R.layout.activity_view_post_detail);
 | 
			
		||||
 | 
			
		||||
@@ -526,69 +534,38 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
 | 
			
		||||
        Handler handler = new Handler(Looper.getMainLooper());
 | 
			
		||||
 | 
			
		||||
        if (postType != HistoryPostPagingSource.TYPE_READ_POSTS) {
 | 
			
		||||
            int nextPage = posts.size() / 25 + 1;
 | 
			
		||||
 | 
			
		||||
            mExecutor.execute(() -> {
 | 
			
		||||
                RedditAPI api = (mAccessToken == null ? mRetrofit.getRetrofit() : mOauthRetrofit).create(RedditAPI.class);
 | 
			
		||||
                LemmyAPI api = mRetrofit.getRetrofit().create(LemmyAPI.class);
 | 
			
		||||
                Call<String> call;
 | 
			
		||||
                String afterKey = posts.isEmpty() ? null : posts.get(posts.size() - 1).getFullName();
 | 
			
		||||
 | 
			
		||||
                switch (postType) {
 | 
			
		||||
                    case PostPagingSource.TYPE_SUBREDDIT:
 | 
			
		||||
                        if (mAccessToken == null) {
 | 
			
		||||
                            call = api.getSubredditBestPosts(subredditName, sortType, sortTime, afterKey);
 | 
			
		||||
                        } else {
 | 
			
		||||
                            call = api.getSubredditBestPostsOauth(subredditName, sortType,
 | 
			
		||||
                                   sortTime, afterKey, APIUtils.getOAuthHeader(mAccessToken));
 | 
			
		||||
                        }
 | 
			
		||||
                        call = api.getPosts(null, sortType.value, nextPage, 25, null, post.getSubredditNamePrefixed(), false, mAccessToken);
 | 
			
		||||
                        break;
 | 
			
		||||
                    case PostPagingSource.TYPE_USER:
 | 
			
		||||
                        if (mAccessToken == null) {
 | 
			
		||||
                            call = api.getUserPosts(username, afterKey, sortType, sortTime);
 | 
			
		||||
                        } else {
 | 
			
		||||
                            call = api.getUserPostsOauth(username, userWhere, afterKey, sortType,
 | 
			
		||||
                                    sortTime, APIUtils.getOAuthHeader(mAccessToken));
 | 
			
		||||
                        }
 | 
			
		||||
                        call = api.getUserPosts(username, sortType.value, nextPage, 25, false, mAccessToken);
 | 
			
		||||
                        break;
 | 
			
		||||
                    case PostPagingSource.TYPE_SEARCH:
 | 
			
		||||
                        if (subredditName == null) {
 | 
			
		||||
                            if (mAccessToken == null) {
 | 
			
		||||
                                call = api.searchPosts(query, afterKey, sortType, sortTime,
 | 
			
		||||
                                        trendingSource);
 | 
			
		||||
                            } else {
 | 
			
		||||
                                call = api.searchPostsOauth(query, afterKey, sortType,
 | 
			
		||||
                                        sortTime, trendingSource, APIUtils.getOAuthHeader(mAccessToken));
 | 
			
		||||
                            }
 | 
			
		||||
                        } else {
 | 
			
		||||
                            if (mAccessToken == null) {
 | 
			
		||||
                                call = api.searchPostsInSpecificSubreddit(subredditName, query,
 | 
			
		||||
                                        sortType, sortTime, afterKey);
 | 
			
		||||
                            } else {
 | 
			
		||||
                                call = api.searchPostsInSpecificSubredditOauth(subredditName, query,
 | 
			
		||||
                                        sortType, sortTime, afterKey,
 | 
			
		||||
                                        APIUtils.getOAuthHeader(mAccessToken));
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                        call = api.search(query, null, subredditName, null, "Post", sortType.value, "All", nextPage, 25, mAccessToken);
 | 
			
		||||
                        break;
 | 
			
		||||
                    case PostPagingSource.TYPE_MULTI_REDDIT:
 | 
			
		||||
                        if (mAccessToken == null) {
 | 
			
		||||
                            call = api.getMultiRedditPosts(multiPath, afterKey, sortTime);
 | 
			
		||||
                        } else {
 | 
			
		||||
                            call = api.getMultiRedditPostsOauth(multiPath, afterKey,
 | 
			
		||||
                                    sortTime, APIUtils.getOAuthHeader(mAccessToken));
 | 
			
		||||
                        }
 | 
			
		||||
                        break;
 | 
			
		||||
                        // TODO: Implement multi community
 | 
			
		||||
 | 
			
		||||
                    case PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE:
 | 
			
		||||
                        //case PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT
 | 
			
		||||
                        call = api.getSubredditBestPosts(subredditName, sortType, sortTime, afterKey);
 | 
			
		||||
                        break;
 | 
			
		||||
                        // TODO: Implement anonymous front page
 | 
			
		||||
 | 
			
		||||
                    default:
 | 
			
		||||
                        call = api.getBestPosts(sortType, sortTime, afterKey,
 | 
			
		||||
                                APIUtils.getOAuthHeader(mAccessToken));
 | 
			
		||||
                        String type = (subredditName.equals("all")) ? "All" : (subredditName.equals("local")) ? "Local" : "Subscribed";
 | 
			
		||||
                        call = api.getPosts(type, sortType.value, nextPage, 25, null, null, false, mAccessToken);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                try {
 | 
			
		||||
                    Response<String> response = call.execute();
 | 
			
		||||
                    if (response.isSuccessful()) {
 | 
			
		||||
                        String responseString = response.body();
 | 
			
		||||
                        LinkedHashSet<Post> newPosts = ParsePost.parsePostsSync(responseString, -1, postFilter, readPostList);
 | 
			
		||||
                        LinkedHashSet<Post> newPosts = ParsePost.parsePostsSync(responseString, -1, postFilter, readPostList, postEnricher);
 | 
			
		||||
                        if (newPosts == null) {
 | 
			
		||||
                            handler.post(() -> {
 | 
			
		||||
                                loadingMorePostsStatus = LoadingMorePostsStatus.NO_MORE_POSTS;
 | 
			
		||||
@@ -670,7 +647,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
 | 
			
		||||
                    Response<String> response = historyPosts.execute();
 | 
			
		||||
                    if (response.isSuccessful()) {
 | 
			
		||||
                        String responseString = response.body();
 | 
			
		||||
                        LinkedHashSet<Post> newPosts = ParsePost.parsePostsSync(responseString, -1, postFilter, null);
 | 
			
		||||
                        LinkedHashSet<Post> newPosts = ParsePost.parsePostsSync(responseString, -1, postFilter, null, postEnricher);
 | 
			
		||||
                        if (newPosts == null || newPosts.isEmpty()) {
 | 
			
		||||
                            handler.post(() -> {
 | 
			
		||||
                                loadingMorePostsStatus = LoadingMorePostsStatus.NO_MORE_POSTS;
 | 
			
		||||
 
 | 
			
		||||
@@ -1518,7 +1518,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
 | 
			
		||||
            if (i == EditorInfo.IME_ACTION_DONE) {
 | 
			
		||||
                Utils.hideKeyboard(this);
 | 
			
		||||
                Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
 | 
			
		||||
                subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString());
 | 
			
		||||
                String communityName = thingEditText.getText().toString();
 | 
			
		||||
                if (communityName.startsWith("!")) {
 | 
			
		||||
                    communityName = communityName.substring(1);
 | 
			
		||||
                }
 | 
			
		||||
                subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName);
 | 
			
		||||
                startActivity(subredditIntent);
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
@@ -1576,7 +1580,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
 | 
			
		||||
                        -> {
 | 
			
		||||
                    Utils.hideKeyboard(this);
 | 
			
		||||
                    Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
 | 
			
		||||
                    subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString());
 | 
			
		||||
                    String communityName = thingEditText.getText().toString();
 | 
			
		||||
                    if (communityName.startsWith("!")) {
 | 
			
		||||
                        communityName = communityName.substring(1);
 | 
			
		||||
                    }
 | 
			
		||||
                    subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName);
 | 
			
		||||
                    startActivity(subredditIntent);
 | 
			
		||||
                })
 | 
			
		||||
                .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
 | 
			
		||||
@@ -1597,7 +1605,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
 | 
			
		||||
            if (i == EditorInfo.IME_ACTION_DONE) {
 | 
			
		||||
                Utils.hideKeyboard(this);
 | 
			
		||||
                Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
 | 
			
		||||
                userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString());
 | 
			
		||||
                String qualifiedName = thingEditText.getText().toString();
 | 
			
		||||
                if (qualifiedName.startsWith("@")) {
 | 
			
		||||
                    qualifiedName = qualifiedName.substring(1);
 | 
			
		||||
                }
 | 
			
		||||
                userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, qualifiedName);
 | 
			
		||||
                startActivity(userIntent);
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
@@ -1610,7 +1622,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
 | 
			
		||||
                        -> {
 | 
			
		||||
                    Utils.hideKeyboard(this);
 | 
			
		||||
                    Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
 | 
			
		||||
                    userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString());
 | 
			
		||||
                    String qualifiedName = thingEditText.getText().toString();
 | 
			
		||||
                    if (qualifiedName.startsWith("@")) {
 | 
			
		||||
                        qualifiedName = qualifiedName.substring(1);
 | 
			
		||||
                    }
 | 
			
		||||
                    userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, qualifiedName);
 | 
			
		||||
                    startActivity(userIntent);
 | 
			
		||||
                })
 | 
			
		||||
                .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
 | 
			
		||||
 
 | 
			
		||||
@@ -1514,7 +1514,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
 | 
			
		||||
            if (i == EditorInfo.IME_ACTION_DONE) {
 | 
			
		||||
                Utils.hideKeyboard(this);
 | 
			
		||||
                Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
 | 
			
		||||
                subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString());
 | 
			
		||||
                String communityName = thingEditText.getText().toString();
 | 
			
		||||
                if (communityName.startsWith("!")) {
 | 
			
		||||
                    communityName = communityName.substring(1);
 | 
			
		||||
                }
 | 
			
		||||
                subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName);
 | 
			
		||||
                startActivity(subredditIntent);
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
@@ -1572,7 +1576,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
 | 
			
		||||
                        -> {
 | 
			
		||||
                    Utils.hideKeyboard(this);
 | 
			
		||||
                    Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
 | 
			
		||||
                    subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString());
 | 
			
		||||
                    String communityName = thingEditText.getText().toString();
 | 
			
		||||
                    if (communityName.startsWith("!")) {
 | 
			
		||||
                        communityName = communityName.substring(1);
 | 
			
		||||
                    }
 | 
			
		||||
                    subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName);
 | 
			
		||||
                    startActivity(subredditIntent);
 | 
			
		||||
                })
 | 
			
		||||
                .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
 | 
			
		||||
@@ -1593,7 +1601,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
 | 
			
		||||
            if (i == EditorInfo.IME_ACTION_DONE) {
 | 
			
		||||
                Utils.hideKeyboard(this);
 | 
			
		||||
                Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
 | 
			
		||||
                userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString());
 | 
			
		||||
                String userName = thingEditText.getText().toString();
 | 
			
		||||
                if (userName.startsWith("@")) {
 | 
			
		||||
                    userName = userName.substring(1);
 | 
			
		||||
                }
 | 
			
		||||
                userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, userName);
 | 
			
		||||
                startActivity(userIntent);
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
@@ -1606,7 +1618,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
 | 
			
		||||
                        -> {
 | 
			
		||||
                    Utils.hideKeyboard(this);
 | 
			
		||||
                    Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
 | 
			
		||||
                    userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString());
 | 
			
		||||
                    String userName = thingEditText.getText().toString();
 | 
			
		||||
                    if (userName.startsWith("@")) {
 | 
			
		||||
                        userName = userName.substring(1);
 | 
			
		||||
                    }
 | 
			
		||||
                    userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, userName);
 | 
			
		||||
                    startActivity(userIntent);
 | 
			
		||||
                })
 | 
			
		||||
                .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
 | 
			
		||||
 
 | 
			
		||||
@@ -108,6 +108,7 @@ import eu.toldi.infinityforlemmy.font.TitleFontFamily;
 | 
			
		||||
import eu.toldi.infinityforlemmy.font.TitleFontStyle;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.FetchPost;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.Post;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
 | 
			
		||||
import eu.toldi.infinityforlemmy.services.DownloadMediaService;
 | 
			
		||||
import eu.toldi.infinityforlemmy.services.DownloadRedditVideoService;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
 | 
			
		||||
@@ -222,10 +223,6 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
 | 
			
		||||
    @Named("default")
 | 
			
		||||
    SharedPreferences mSharedPreferences;
 | 
			
		||||
 | 
			
		||||
    @Inject
 | 
			
		||||
    @Named("current_account")
 | 
			
		||||
    SharedPreferences mCurrentAccountSharedPreferences;
 | 
			
		||||
 | 
			
		||||
    @Inject
 | 
			
		||||
    CustomThemeWrapper mCustomThemeWrapper;
 | 
			
		||||
 | 
			
		||||
@@ -235,6 +232,9 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
 | 
			
		||||
    @Inject
 | 
			
		||||
    SimpleCache mSimpleCache;
 | 
			
		||||
 | 
			
		||||
    @Inject
 | 
			
		||||
    PostEnricher postEnricher;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void onCreate(Bundle savedInstanceState) {
 | 
			
		||||
        super.onCreate(savedInstanceState);
 | 
			
		||||
@@ -756,8 +756,8 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
 | 
			
		||||
                        }
 | 
			
		||||
                    });
 | 
			
		||||
        } else {
 | 
			
		||||
            FetchGfycatOrRedgifsVideoLinks.fetchRedgifsVideoLinks(this, mExecutor, new Handler(), redgifsRetrofit,
 | 
			
		||||
                    mCurrentAccountSharedPreferences, gfycatId, new FetchGfycatOrRedgifsVideoLinks.FetchGfycatOrRedgifsVideoLinksListener() {
 | 
			
		||||
            FetchGfycatOrRedgifsVideoLinks.fetchRedgifsVideoLinks(mExecutor, new Handler(), redgifsRetrofit,
 | 
			
		||||
                    gfycatId, new FetchGfycatOrRedgifsVideoLinks.FetchGfycatOrRedgifsVideoLinksListener() {
 | 
			
		||||
                        @Override
 | 
			
		||||
                        public void success(String webm, String mp4) {
 | 
			
		||||
                            progressBar.setVisibility(View.GONE);
 | 
			
		||||
@@ -791,7 +791,7 @@ public class ViewVideoActivity extends AppCompatActivity implements CustomFontRe
 | 
			
		||||
                    int commentsIndex = segments.lastIndexOf("comments");
 | 
			
		||||
                    String postId = segments.get(commentsIndex + 1);
 | 
			
		||||
                    FetchPost.fetchPost(mExecutor, new Handler(), retrofit.getRetrofit(), postId, null,
 | 
			
		||||
                            new FetchPost.FetchPostListener() {
 | 
			
		||||
                            postEnricher, new FetchPost.FetchPostListener() {
 | 
			
		||||
                                @Override
 | 
			
		||||
                                public void fetchPostSuccess(Post post) {
 | 
			
		||||
                                    if (post.isGfycat()) {
 | 
			
		||||
 
 | 
			
		||||
@@ -15,6 +15,7 @@ import com.bumptech.glide.request.RequestOptions;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.concurrent.Executor;
 | 
			
		||||
import java.util.regex.Pattern;
 | 
			
		||||
 | 
			
		||||
import butterknife.BindView;
 | 
			
		||||
import butterknife.ButterKnife;
 | 
			
		||||
@@ -186,6 +187,10 @@ public class BlockedCommunitiesRecyclerViewAdapter extends RecyclerView.Adapter<
 | 
			
		||||
                        .into(((SubredditViewHolder) viewHolder).iconGifImageView);
 | 
			
		||||
            }
 | 
			
		||||
            ((SubredditViewHolder) viewHolder).subredditNameTextView.setText(name);
 | 
			
		||||
            if (fullname.contains("@")) {
 | 
			
		||||
                ((SubredditViewHolder) viewHolder).communityInstanceTextView.setText("@" + fullname.split(Pattern.quote("@"), 2)[1]);
 | 
			
		||||
                ((SubredditViewHolder) viewHolder).communityInstanceTextView.setTextColor(CustomThemeWrapper.darkenColor(primaryTextColor, 0.7f));
 | 
			
		||||
            }
 | 
			
		||||
        } else if (viewHolder instanceof FavoriteSubredditViewHolder) {
 | 
			
		||||
            int offset;
 | 
			
		||||
            if (itemClickListener != null) {
 | 
			
		||||
@@ -318,6 +323,9 @@ public class BlockedCommunitiesRecyclerViewAdapter extends RecyclerView.Adapter<
 | 
			
		||||
        @BindView(R.id.thing_name_text_view_item_subscribed_thing)
 | 
			
		||||
        TextView subredditNameTextView;
 | 
			
		||||
 | 
			
		||||
        @BindView(R.id.thing_instance_text_view_item_subscribed_thing)
 | 
			
		||||
        TextView communityInstanceTextView;
 | 
			
		||||
 | 
			
		||||
        SubredditViewHolder(View itemView) {
 | 
			
		||||
            super(itemView);
 | 
			
		||||
            ButterKnife.bind(this, itemView);
 | 
			
		||||
 
 | 
			
		||||
@@ -139,7 +139,6 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
 | 
			
		||||
    private BaseActivity mActivity;
 | 
			
		||||
    private HistoryPostFragment mFragment;
 | 
			
		||||
    private SharedPreferences mSharedPreferences;
 | 
			
		||||
    private SharedPreferences mCurrentAccountSharedPreferences;
 | 
			
		||||
    private Executor mExecutor;
 | 
			
		||||
    private Retrofit retrofit;
 | 
			
		||||
    private Retrofit mGfycatRetrofit;
 | 
			
		||||
@@ -227,7 +226,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
 | 
			
		||||
                                          Retrofit gfycatRetrofit, Retrofit redgifsRetrofit, Provider<StreamableAPI> streambleApiProvider,
 | 
			
		||||
                                          CustomThemeWrapper customThemeWrapper, Locale locale,
 | 
			
		||||
                                          String accessToken, String accountName, int postType, int postLayout, boolean displaySubredditName,
 | 
			
		||||
                                          SharedPreferences sharedPreferences, SharedPreferences currentAccountSharedPreferences,
 | 
			
		||||
                                          SharedPreferences sharedPreferences,
 | 
			
		||||
                                          SharedPreferences nsfwAndSpoilerSharedPreferences,
 | 
			
		||||
                                          ExoCreator exoCreator, Callback callback) {
 | 
			
		||||
        super(DIFF_CALLBACK);
 | 
			
		||||
@@ -235,7 +234,6 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
 | 
			
		||||
            mActivity = activity;
 | 
			
		||||
            mFragment = fragment;
 | 
			
		||||
            mSharedPreferences = sharedPreferences;
 | 
			
		||||
            mCurrentAccountSharedPreferences = currentAccountSharedPreferences;
 | 
			
		||||
            mExecutor = executor;
 | 
			
		||||
            retrofit = oauthRetrofit;
 | 
			
		||||
            mGfycatRetrofit = gfycatRetrofit;
 | 
			
		||||
@@ -698,7 +696,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
 | 
			
		||||
                    if ((post.isGfycat() || post.isRedgifs()) && !post.isLoadGfycatOrStreamableVideoSuccess()) {
 | 
			
		||||
                        ((PostVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall =
 | 
			
		||||
                                post.isGfycat() ? mGfycatRetrofit.create(GfycatAPI.class).getGfycatData(post.getGfycatId()) :
 | 
			
		||||
                                        mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(APIUtils.getRedgifsOAuthHeader(mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "")), post.getGfycatId(), APIUtils.USER_AGENT);
 | 
			
		||||
                                        mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(post.getGfycatId());
 | 
			
		||||
                        FetchGfycatOrRedgifsVideoLinks.fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(mExecutor, new Handler(),
 | 
			
		||||
                                ((PostVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall,
 | 
			
		||||
                                post.isGfycat(), mAutomaticallyTryRedgifs,
 | 
			
		||||
@@ -875,7 +873,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter<Post, Recy
 | 
			
		||||
                    if ((post.isGfycat() || post.isRedgifs()) && !post.isLoadGfycatOrStreamableVideoSuccess()) {
 | 
			
		||||
                        ((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall =
 | 
			
		||||
                                post.isGfycat() ? mGfycatRetrofit.create(GfycatAPI.class).getGfycatData(post.getGfycatId()) :
 | 
			
		||||
                                        mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(APIUtils.getRedgifsOAuthHeader(mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "")), post.getGfycatId(), APIUtils.USER_AGENT);
 | 
			
		||||
                                        mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(post.getGfycatId());
 | 
			
		||||
                        FetchGfycatOrRedgifsVideoLinks.fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(mExecutor, new Handler(),
 | 
			
		||||
                                ((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall,
 | 
			
		||||
                                post.isGfycat(), mAutomaticallyTryRedgifs,
 | 
			
		||||
 
 | 
			
		||||
@@ -698,7 +698,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
 | 
			
		||||
                if (mPost.isGfycat() || mPost.isRedgifs() && !mPost.isLoadGfycatOrStreamableVideoSuccess()) {
 | 
			
		||||
                    ((PostDetailVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall =
 | 
			
		||||
                            mPost.isGfycat() ? mGfycatRetrofit.create(GfycatAPI.class).getGfycatData(mPost.getGfycatId()) :
 | 
			
		||||
                                    mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(APIUtils.getRedgifsOAuthHeader(mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "")), mPost.getGfycatId(), APIUtils.USER_AGENT);
 | 
			
		||||
                                    mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(mPost.getGfycatId());
 | 
			
		||||
                    FetchGfycatOrRedgifsVideoLinks.fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(mExecutor, new Handler(),
 | 
			
		||||
                            ((PostDetailVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall,
 | 
			
		||||
                            mPost.isGfycat(), mAutomaticallyTryRedgifs,
 | 
			
		||||
 
 | 
			
		||||
@@ -787,7 +787,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
 | 
			
		||||
                    if ((post.isGfycat() || post.isRedgifs()) && !post.isLoadGfycatOrStreamableVideoSuccess()) {
 | 
			
		||||
                        ((PostVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall =
 | 
			
		||||
                                post.isGfycat() ? mGfycatRetrofit.create(GfycatAPI.class).getGfycatData(post.getGfycatId()) :
 | 
			
		||||
                                        mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(APIUtils.getRedgifsOAuthHeader(mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "")), post.getGfycatId(), APIUtils.USER_AGENT);
 | 
			
		||||
                                        mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(post.getGfycatId());
 | 
			
		||||
                        FetchGfycatOrRedgifsVideoLinks.fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(mExecutor, new Handler(),
 | 
			
		||||
                                ((PostVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall,
 | 
			
		||||
                                post.isGfycat(), mAutomaticallyTryRedgifs,
 | 
			
		||||
@@ -979,7 +979,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
 | 
			
		||||
                    if ((post.isGfycat() || post.isRedgifs()) && !post.isLoadGfycatOrStreamableVideoSuccess()) {
 | 
			
		||||
                        ((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall =
 | 
			
		||||
                                post.isGfycat() ? mGfycatRetrofit.create(GfycatAPI.class).getGfycatData(post.getGfycatId()) :
 | 
			
		||||
                                        mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(APIUtils.getRedgifsOAuthHeader(mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.REDGIFS_ACCESS_TOKEN, "")), post.getGfycatId(), APIUtils.USER_AGENT);
 | 
			
		||||
                                        mRedgifsRetrofit.create(RedgifsAPI.class).getRedgifsData(post.getGfycatId());
 | 
			
		||||
                        FetchGfycatOrRedgifsVideoLinks.fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(mExecutor, new Handler(),
 | 
			
		||||
                                ((PostCard2VideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall,
 | 
			
		||||
                                post.isGfycat(), mAutomaticallyTryRedgifs,
 | 
			
		||||
 
 | 
			
		||||
@@ -141,7 +141,8 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred
 | 
			
		||||
                            .into(((DataViewHolder) holder).iconGifImageView);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                ((DataViewHolder) holder).subredditNameTextView.setText(subredditData.getName());
 | 
			
		||||
                ((DataViewHolder) holder).subredditNameTextView.setText(subredditData.getTitle());
 | 
			
		||||
                ((DataViewHolder) holder).communityInstanceTextView.setText('@' + LemmyUtils.actorID2FullName(subredditData.getActorId()).split("@")[1]);
 | 
			
		||||
                ((DataViewHolder) holder).subscriberCountTextView.setText(activity.getString(R.string.subscribers_number_detail, subredditData.getNSubscribers()));
 | 
			
		||||
 | 
			
		||||
                if (!isMultiSelection) {
 | 
			
		||||
@@ -262,6 +263,9 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred
 | 
			
		||||
        GifImageView iconGifImageView;
 | 
			
		||||
        @BindView(R.id.subreddit_name_text_view_item_subreddit_listing)
 | 
			
		||||
        TextView subredditNameTextView;
 | 
			
		||||
 | 
			
		||||
        @BindView(R.id.community_instance_text_view_item_subreddit_listing)
 | 
			
		||||
        TextView communityInstanceTextView;
 | 
			
		||||
        @BindView(R.id.subscriber_count_text_view_item_subreddit_listing)
 | 
			
		||||
        TextView subscriberCountTextView;
 | 
			
		||||
        @BindView(R.id.subscribe_image_view_item_subreddit_listing)
 | 
			
		||||
@@ -273,6 +277,7 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred
 | 
			
		||||
            super(itemView);
 | 
			
		||||
            ButterKnife.bind(this, itemView);
 | 
			
		||||
            subredditNameTextView.setTextColor(primaryTextColor);
 | 
			
		||||
            communityInstanceTextView.setTextColor(CustomThemeWrapper.darkenColor(primaryTextColor, 0.7f));
 | 
			
		||||
            subscriberCountTextView.setTextColor(secondaryTextColor);
 | 
			
		||||
            subscribeButton.setColorFilter(unsubscribed, android.graphics.PorterDuff.Mode.SRC_IN);
 | 
			
		||||
            if (isMultiSelection) {
 | 
			
		||||
 
 | 
			
		||||
@@ -84,12 +84,10 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
 | 
			
		||||
        if (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) {
 | 
			
		||||
            if (itemClickListener != null && !hasClearSelectionRow) {
 | 
			
		||||
                if (position == 0) {
 | 
			
		||||
                    return VIEW_TYPE_SUBREDDIT;
 | 
			
		||||
                } else if (position == 1) {
 | 
			
		||||
                    return VIEW_TYPE_FAVORITE_SUBREDDIT_DIVIDER;
 | 
			
		||||
                } else if (position == mFavoriteSubscribedSubredditData.size() + 1) {
 | 
			
		||||
                    return VIEW_TYPE_SUBREDDIT_DIVIDER;
 | 
			
		||||
                } else if (position < mFavoriteSubscribedSubredditData.size() + 1) {
 | 
			
		||||
                } else if (position <= mFavoriteSubscribedSubredditData.size()) {
 | 
			
		||||
                    return VIEW_TYPE_FAVORITE_SUBREDDIT;
 | 
			
		||||
                } else {
 | 
			
		||||
                    return VIEW_TYPE_SUBREDDIT;
 | 
			
		||||
@@ -160,7 +158,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
 | 
			
		||||
                                mFavoriteSubscribedSubredditData.size() + 3 : 1;
 | 
			
		||||
                    } else {
 | 
			
		||||
                        offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
 | 
			
		||||
                                mFavoriteSubscribedSubredditData.size() + 3 : 1;
 | 
			
		||||
                                mFavoriteSubscribedSubredditData.size() + 2 : 0;
 | 
			
		||||
                    }
 | 
			
		||||
                } else {
 | 
			
		||||
                    offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
 | 
			
		||||
@@ -222,19 +220,23 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
 | 
			
		||||
                        .into(((SubredditViewHolder) viewHolder).iconGifImageView);
 | 
			
		||||
            }
 | 
			
		||||
            ((SubredditViewHolder) viewHolder).subredditNameTextView.setText(name);
 | 
			
		||||
            if (fullname.contains("@")) {
 | 
			
		||||
                ((SubredditViewHolder) viewHolder).communityInstanceTextView.setText(fullname.substring(fullname.indexOf("@")));
 | 
			
		||||
            }
 | 
			
		||||
        } else if (viewHolder instanceof FavoriteSubredditViewHolder) {
 | 
			
		||||
            int offset;
 | 
			
		||||
            if (itemClickListener != null) {
 | 
			
		||||
                if (hasClearSelectionRow) {
 | 
			
		||||
                    offset = 2;
 | 
			
		||||
                } else {
 | 
			
		||||
                    offset = 2;
 | 
			
		||||
                    offset = 1;
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                offset = 1;
 | 
			
		||||
            }
 | 
			
		||||
            SubscribedSubredditData communityData = mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset);
 | 
			
		||||
            String name = mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getName();
 | 
			
		||||
            String fullname = mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getQualified_name();
 | 
			
		||||
            String iconUrl = mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).getIconUrl();
 | 
			
		||||
 | 
			
		||||
            if (mFavoriteSubscribedSubredditData.get(viewHolder.getBindingAdapterPosition() - offset).isFavorite()) {
 | 
			
		||||
@@ -280,6 +282,9 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
 | 
			
		||||
                        .into(((FavoriteSubredditViewHolder) viewHolder).iconGifImageView);
 | 
			
		||||
            }
 | 
			
		||||
            ((FavoriteSubredditViewHolder) viewHolder).subredditNameTextView.setText(name);
 | 
			
		||||
            if (fullname.contains("@")) {
 | 
			
		||||
                ((FavoriteSubredditViewHolder) viewHolder).communityInstanceTextView.setText(fullname.substring(fullname.indexOf("@")));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -289,14 +294,14 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
 | 
			
		||||
            if (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) {
 | 
			
		||||
                if (itemClickListener != null) {
 | 
			
		||||
                    return mSubscribedSubredditData.size() > 0 ?
 | 
			
		||||
                            mFavoriteSubscribedSubredditData.size() + mSubscribedSubredditData.size() + 3 : 0;
 | 
			
		||||
                            mFavoriteSubscribedSubredditData.size() + mSubscribedSubredditData.size() + ((hasClearSelectionRow) ? 3 : 2) : 0;
 | 
			
		||||
                }
 | 
			
		||||
                return mSubscribedSubredditData.size() > 0 ?
 | 
			
		||||
                        mFavoriteSubscribedSubredditData.size() + mSubscribedSubredditData.size() + 2 : 0;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (itemClickListener != null) {
 | 
			
		||||
                return mSubscribedSubredditData.size() > 0 ? mSubscribedSubredditData.size() + 1 : 0;
 | 
			
		||||
                return (hasClearSelectionRow) ? mSubscribedSubredditData.size() + 1 : mSubscribedSubredditData.size();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return mSubscribedSubredditData.size();
 | 
			
		||||
@@ -349,7 +354,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
 | 
			
		||||
                                    mFavoriteSubscribedSubredditData.size() + 3 : 0;
 | 
			
		||||
                        } else {
 | 
			
		||||
                            offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
 | 
			
		||||
                                    mFavoriteSubscribedSubredditData.size() + 3 : 0;
 | 
			
		||||
                                    mFavoriteSubscribedSubredditData.size() + 2 : 0;
 | 
			
		||||
                        }
 | 
			
		||||
                    } else {
 | 
			
		||||
                        offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
 | 
			
		||||
@@ -364,7 +369,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
 | 
			
		||||
                    if (hasClearSelectionRow) {
 | 
			
		||||
                        offset = 2;
 | 
			
		||||
                    } else {
 | 
			
		||||
                        offset = 2;
 | 
			
		||||
                        offset = 1;
 | 
			
		||||
                    }
 | 
			
		||||
                } else {
 | 
			
		||||
                    offset = 1;
 | 
			
		||||
@@ -384,6 +389,9 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
 | 
			
		||||
        GifImageView iconGifImageView;
 | 
			
		||||
        @BindView(R.id.thing_name_text_view_item_subscribed_thing)
 | 
			
		||||
        TextView subredditNameTextView;
 | 
			
		||||
 | 
			
		||||
        @BindView(R.id.thing_instance_text_view_item_subscribed_thing)
 | 
			
		||||
        TextView communityInstanceTextView;
 | 
			
		||||
        @BindView(R.id.favorite_image_view_item_subscribed_thing)
 | 
			
		||||
        ImageView favoriteImageView;
 | 
			
		||||
 | 
			
		||||
@@ -392,8 +400,10 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
 | 
			
		||||
            ButterKnife.bind(this, itemView);
 | 
			
		||||
            if (mActivity.typeface != null) {
 | 
			
		||||
                subredditNameTextView.setTypeface(mActivity.typeface);
 | 
			
		||||
                communityInstanceTextView.setTypeface(mActivity.typeface);
 | 
			
		||||
            }
 | 
			
		||||
            subredditNameTextView.setTextColor(primaryTextColor);
 | 
			
		||||
            communityInstanceTextView.setTextColor(CustomThemeWrapper.darkenColor(primaryTextColor, 0.7f));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -402,6 +412,9 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
 | 
			
		||||
        GifImageView iconGifImageView;
 | 
			
		||||
        @BindView(R.id.thing_name_text_view_item_subscribed_thing)
 | 
			
		||||
        TextView subredditNameTextView;
 | 
			
		||||
 | 
			
		||||
        @BindView(R.id.thing_instance_text_view_item_subscribed_thing)
 | 
			
		||||
        TextView communityInstanceTextView;
 | 
			
		||||
        @BindView(R.id.favorite_image_view_item_subscribed_thing)
 | 
			
		||||
        ImageView favoriteImageView;
 | 
			
		||||
 | 
			
		||||
@@ -411,8 +424,10 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
 | 
			
		||||
            ButterKnife.bind(this, itemView);
 | 
			
		||||
            if (mActivity.typeface != null) {
 | 
			
		||||
                subredditNameTextView.setTypeface(mActivity.typeface);
 | 
			
		||||
                communityInstanceTextView.setTypeface(mActivity.typeface);
 | 
			
		||||
            }
 | 
			
		||||
            subredditNameTextView.setTextColor(primaryTextColor);
 | 
			
		||||
            communityInstanceTextView.setTextColor(CustomThemeWrapper.darkenColor(primaryTextColor, 0.7f));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -136,7 +136,9 @@ public class UserListingRecyclerViewAdapter extends PagedListAdapter<UserData, R
 | 
			
		||||
                            .into(((DataViewHolder) holder).iconGifImageView);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                ((DataViewHolder) holder).userNameTextView.setText(userData.getName());
 | 
			
		||||
                ((DataViewHolder) holder).userNameTextView.setText(userData.getTitle().equals("") ? userData.getName() : userData.getTitle());
 | 
			
		||||
                String qualifiedName = LemmyUtils.actorID2FullName(userData.getActorId());
 | 
			
		||||
                ((DataViewHolder) holder).userInstanceTextView.setText(qualifiedName.substring(qualifiedName.indexOf('@')));
 | 
			
		||||
 | 
			
		||||
                if (!isMultiSelection) {
 | 
			
		||||
                    CheckIsFollowingUser.checkIsFollowingUser(executor, new Handler(), redditDataRoomDatabase,
 | 
			
		||||
@@ -237,6 +239,9 @@ public class UserListingRecyclerViewAdapter extends PagedListAdapter<UserData, R
 | 
			
		||||
        GifImageView iconGifImageView;
 | 
			
		||||
        @BindView(R.id.user_name_text_view_item_user_listing)
 | 
			
		||||
        TextView userNameTextView;
 | 
			
		||||
 | 
			
		||||
        @BindView(R.id.user_instance_text_view_item_user_listing)
 | 
			
		||||
        TextView userInstanceTextView;
 | 
			
		||||
        @BindView(R.id.subscribe_image_view_item_user_listing)
 | 
			
		||||
        ImageView subscribeButton;
 | 
			
		||||
        @BindView(R.id.checkbox__item_user_listing)
 | 
			
		||||
@@ -246,6 +251,7 @@ public class UserListingRecyclerViewAdapter extends PagedListAdapter<UserData, R
 | 
			
		||||
            super(itemView);
 | 
			
		||||
            ButterKnife.bind(this, itemView);
 | 
			
		||||
            userNameTextView.setTextColor(primaryTextColor);
 | 
			
		||||
            userInstanceTextView.setTextColor(CustomThemeWrapper.darkenColor(primaryTextColor, 0.7f));
 | 
			
		||||
            subscribeButton.setColorFilter(unsubscribedColor, android.graphics.PorterDuff.Mode.SRC_IN);
 | 
			
		||||
 | 
			
		||||
            if (activity.typeface != null) {
 | 
			
		||||
 
 | 
			
		||||
@@ -101,7 +101,16 @@ public interface LemmyAPI {
 | 
			
		||||
    Call<String> postDelete(@Body DeletePostDTO params);
 | 
			
		||||
 | 
			
		||||
    @GET("api/v3/user")
 | 
			
		||||
    ListenableFuture<Response<String>> getUserPosts(
 | 
			
		||||
    ListenableFuture<Response<String>> getUserPostsListenableFuture(
 | 
			
		||||
            @Query("username") String username,
 | 
			
		||||
            @Query("sort") String sort,
 | 
			
		||||
            @Query("page") Integer page,
 | 
			
		||||
            @Query("limit") Integer limit,
 | 
			
		||||
            @Query("saved_only") Boolean saved_only,
 | 
			
		||||
            @Query("auth") String access_token);
 | 
			
		||||
 | 
			
		||||
    @GET("api/v3/user")
 | 
			
		||||
    Call<String> getUserPosts(
 | 
			
		||||
            @Query("username") String username,
 | 
			
		||||
            @Query("sort") String sort,
 | 
			
		||||
            @Query("page") Integer page,
 | 
			
		||||
@@ -129,7 +138,19 @@ public interface LemmyAPI {
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    @GET("api/v3/post/list")
 | 
			
		||||
    ListenableFuture<Response<String>> getPosts(
 | 
			
		||||
    ListenableFuture<Response<String>> getPostsListenableFuture(
 | 
			
		||||
            @Query("type_") String type_,
 | 
			
		||||
            @Query("sort") String sort,
 | 
			
		||||
            @Query("page") Integer page,
 | 
			
		||||
            @Query("limit") Integer limit,
 | 
			
		||||
            @Query("community_id") Integer community_id,
 | 
			
		||||
            @Query("community_name") String community_name,
 | 
			
		||||
            @Query("saved_only") Boolean saved_only,
 | 
			
		||||
            @Query("auth") String auth
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    @GET("api/v3/post/list")
 | 
			
		||||
    Call<String> getPosts(
 | 
			
		||||
            @Query("type_") String type_,
 | 
			
		||||
            @Query("sort") String sort,
 | 
			
		||||
            @Query("page") Integer page,
 | 
			
		||||
 
 | 
			
		||||
@@ -6,14 +6,16 @@ import retrofit2.Call;
 | 
			
		||||
import retrofit2.http.FieldMap;
 | 
			
		||||
import retrofit2.http.FormUrlEncoded;
 | 
			
		||||
import retrofit2.http.GET;
 | 
			
		||||
import retrofit2.http.HeaderMap;
 | 
			
		||||
import retrofit2.http.POST;
 | 
			
		||||
import retrofit2.http.Path;
 | 
			
		||||
import retrofit2.http.Query;
 | 
			
		||||
 | 
			
		||||
public interface RedgifsAPI {
 | 
			
		||||
    @GET("/v2/gifs/{id}")
 | 
			
		||||
    Call<String> getRedgifsData(@HeaderMap Map<String, String> headers, @Path("id") String id, @Query("user-agent") String userAgent);
 | 
			
		||||
    Call<String> getRedgifsData(@Path("id") String id);
 | 
			
		||||
 | 
			
		||||
    @GET("/v2/gifs")
 | 
			
		||||
    Call<String> getRedgifsMultipleData(@Query("ids") String ids);
 | 
			
		||||
 | 
			
		||||
    @FormUrlEncoded
 | 
			
		||||
    @POST("/v2/oauth/client")
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@ package eu.toldi.infinityforlemmy.asynctasks;
 | 
			
		||||
 | 
			
		||||
import android.content.SharedPreferences;
 | 
			
		||||
import android.os.Handler;
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
 | 
			
		||||
import java.util.concurrent.Executor;
 | 
			
		||||
 | 
			
		||||
@@ -25,18 +26,31 @@ public class SwitchAccount {
 | 
			
		||||
                    .putString(SharedPreferencesUtils.ACCESS_TOKEN, account.getAccessToken())
 | 
			
		||||
                    .putString(SharedPreferencesUtils.ACCOUNT_NAME, account.getDisplay_name())
 | 
			
		||||
                    .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();
 | 
			
		||||
            retrofitHolder.setBaseURL(account.getInstance_url());
 | 
			
		||||
            retrofitHolder.setAccessToken(null);
 | 
			
		||||
            FetchSiteInfo.fetchSiteInfo(retrofitHolder.getRetrofit(), account.getAccessToken(), new FetchSiteInfo.FetchSiteInfoListener() {
 | 
			
		||||
                @Override
 | 
			
		||||
                public void onFetchSiteInfoSuccess(SiteInfo siteInfo) {
 | 
			
		||||
                    boolean canDownvote = siteInfo.isEnable_downvotes();
 | 
			
		||||
                    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
 | 
			
		||||
                public void onFetchSiteInfoFailed() {
 | 
			
		||||
                    Log.e("SwitchAccount", "Failed to fetch site info");
 | 
			
		||||
                    currentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.CAN_DOWNVOTE, true).apply();
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
 
 | 
			
		||||
@@ -124,6 +124,7 @@ import eu.toldi.infinityforlemmy.events.ShowThumbnailOnTheRightInCompactLayoutEv
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.HistoryPostPagingSource;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.HistoryPostViewModel;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.Post;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
 | 
			
		||||
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
 | 
			
		||||
import eu.toldi.infinityforlemmy.postfilter.PostFilterUsage;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
 | 
			
		||||
@@ -178,9 +179,6 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato
 | 
			
		||||
    @Named("default")
 | 
			
		||||
    SharedPreferences mSharedPreferences;
 | 
			
		||||
    @Inject
 | 
			
		||||
    @Named("current_account")
 | 
			
		||||
    SharedPreferences mCurrentAccountSharedPreferences;
 | 
			
		||||
    @Inject
 | 
			
		||||
    @Named("post_layout")
 | 
			
		||||
    SharedPreferences mPostLayoutSharedPreferences;
 | 
			
		||||
    @Inject
 | 
			
		||||
@@ -198,6 +196,8 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato
 | 
			
		||||
    ExoCreator mExoCreator;
 | 
			
		||||
    @Inject
 | 
			
		||||
    Executor mExecutor;
 | 
			
		||||
    @Inject
 | 
			
		||||
    PostEnricher postEnricher;
 | 
			
		||||
    private RequestManager mGlide;
 | 
			
		||||
    private BaseActivity activity;
 | 
			
		||||
    private LinearLayoutManagerBugFixed mLinearLayoutManager;
 | 
			
		||||
@@ -383,7 +383,7 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato
 | 
			
		||||
            mAdapter = new HistoryPostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit.getRetrofit(), mGfycatRetrofit,
 | 
			
		||||
                    mRedgifsRetrofit, mStreamableApiProvider, mCustomThemeWrapper, locale,
 | 
			
		||||
                    accessToken, accountName, postType, postLayout, true,
 | 
			
		||||
                    mSharedPreferences, mCurrentAccountSharedPreferences, mNsfwAndSpoilerSharedPreferences,
 | 
			
		||||
                    mSharedPreferences, mNsfwAndSpoilerSharedPreferences,
 | 
			
		||||
                    mExoCreator, new HistoryPostRecyclerViewAdapter.Callback() {
 | 
			
		||||
                @Override
 | 
			
		||||
                public void typeChipClicked(int filter) {
 | 
			
		||||
@@ -654,15 +654,10 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void initializeAndBindPostViewModel(String accessToken) {
 | 
			
		||||
        if (postType == HistoryPostPagingSource.TYPE_READ_POSTS) {
 | 
			
		||||
            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);
 | 
			
		||||
        } 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);
 | 
			
		||||
        }
 | 
			
		||||
        mHistoryPostViewModel = new ViewModelProvider(HistoryPostFragment.this, new HistoryPostViewModel.Factory(mExecutor,
 | 
			
		||||
                accessToken == null ? mRetrofit.getRetrofit() : mOauthRetrofit, mRedditDataRoomDatabase, accessToken,
 | 
			
		||||
                accountName, mSharedPreferences, HistoryPostPagingSource.TYPE_READ_POSTS, postFilter, postEnricher))
 | 
			
		||||
                .get(HistoryPostViewModel.class);
 | 
			
		||||
 | 
			
		||||
        bindPostViewModel();
 | 
			
		||||
    }
 | 
			
		||||
@@ -1447,4 +1442,4 @@ public class HistoryPostFragment extends Fragment implements FragmentCommunicato
 | 
			
		||||
    public interface LoadIconListener {
 | 
			
		||||
        void loadIconSuccess(String subredditOrUserName, String iconUrl);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -135,6 +135,7 @@ import eu.toldi.infinityforlemmy.events.ShowThumbnailOnTheRightInCompactLayoutEv
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.Post;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.PostPagingSource;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.PostViewModel;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
 | 
			
		||||
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
 | 
			
		||||
import eu.toldi.infinityforlemmy.postfilter.PostFilterUsage;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
 | 
			
		||||
@@ -222,6 +223,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
 | 
			
		||||
    ExoCreator mExoCreator;
 | 
			
		||||
    @Inject
 | 
			
		||||
    Executor mExecutor;
 | 
			
		||||
    @Inject
 | 
			
		||||
    PostEnricher postEnricher;
 | 
			
		||||
    private RequestManager mGlide;
 | 
			
		||||
    private BaseActivity activity;
 | 
			
		||||
    private LinearLayoutManagerBugFixed mLinearLayoutManager;
 | 
			
		||||
@@ -533,17 +536,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
 | 
			
		||||
                sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + subredditName,
 | 
			
		||||
                        mSharedPreferences.getString(SharedPreferencesUtils.SUBREDDIT_DEFAULT_SORT_TIME, SortType.Time.ALL.name()));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            sortType = newSortType(sort, sortTime);
 | 
			
		||||
 | 
			
		||||
            boolean displaySubredditName = subredditName != null && (subredditName.equals("local") || subredditName.equals("all"));
 | 
			
		||||
            postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, defaultPostLayout);
 | 
			
		||||
            SortType.Type st = SortType.Type.fromValue(sort);
 | 
			
		||||
            st = st == null ? SortType.Type.HOT : st;
 | 
			
		||||
            if (sortTime != null) {
 | 
			
		||||
                st = SortType.Type.fromValue(sortTime);
 | 
			
		||||
                st = st == null ? SortType.Type.TOP_ALL : st;
 | 
			
		||||
                sortType = new SortType(st);
 | 
			
		||||
            } else {
 | 
			
		||||
                sortType = new SortType(st);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit,
 | 
			
		||||
                    mRedgifsRetrofit, mStreamableApiProvider, mCustomThemeWrapper, locale,
 | 
			
		||||
@@ -607,16 +605,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
 | 
			
		||||
                sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath,
 | 
			
		||||
                        SortType.Time.ALL.name());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            sortType = newSortType(sort, sortTime);
 | 
			
		||||
 | 
			
		||||
            postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiRedditPath,
 | 
			
		||||
                    defaultPostLayout);
 | 
			
		||||
 | 
			
		||||
            SortType.Type st = SortType.Type.fromValue(sort);
 | 
			
		||||
            st = st == null ? SortType.Type.HOT : st;
 | 
			
		||||
            if (sortTime != null) {
 | 
			
		||||
                sortType = new SortType(st, SortType.Time.valueOf(sortTime));
 | 
			
		||||
            } else {
 | 
			
		||||
                sortType = new SortType(st);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit,
 | 
			
		||||
                    mRedgifsRetrofit, mStreamableApiProvider, mCustomThemeWrapper, locale,
 | 
			
		||||
@@ -674,17 +668,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
 | 
			
		||||
 | 
			
		||||
            String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username,
 | 
			
		||||
                    mSharedPreferences.getString(SharedPreferencesUtils.USER_DEFAULT_SORT_TYPE, SortType.Type.NEW.name()));
 | 
			
		||||
            SortType.Type st = SortType.Type.fromValue(sort);
 | 
			
		||||
            st = st == null ? SortType.Type.NEW : st;
 | 
			
		||||
            String sortTime = null;
 | 
			
		||||
            if (sort.equalsIgnoreCase(SortType.Type.TOP.value)) {
 | 
			
		||||
                String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username,
 | 
			
		||||
                sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username,
 | 
			
		||||
                        mSharedPreferences.getString(SharedPreferencesUtils.USER_DEFAULT_SORT_TIME, SortType.Time.ALL.name()));
 | 
			
		||||
                st = SortType.Type.fromValue(sortTime);
 | 
			
		||||
                st = st == null ? SortType.Type.NEW : st;
 | 
			
		||||
                sortType = new SortType(st);
 | 
			
		||||
            } else {
 | 
			
		||||
                sortType = new SortType(st);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            sortType = newSortType(sort, sortTime);
 | 
			
		||||
 | 
			
		||||
            postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + username, defaultPostLayout);
 | 
			
		||||
 | 
			
		||||
            mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit,
 | 
			
		||||
@@ -741,14 +732,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
 | 
			
		||||
            subredditName = getArguments().getString(EXTRA_NAME);
 | 
			
		||||
 | 
			
		||||
            String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + "-", SortType.Type.HOT.name());
 | 
			
		||||
            SortType.Type st = SortType.Type.fromValue(sort);
 | 
			
		||||
            st = st == null ? SortType.Type.NEW : st;
 | 
			
		||||
            String sortTime = null;
 | 
			
		||||
            if (sort.equals(SortType.Type.TOP.name())) {
 | 
			
		||||
                String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + "-", SortType.Time.ALL.name());
 | 
			
		||||
                sortType = new SortType(st, SortType.Time.valueOf(sortTime));
 | 
			
		||||
            } else {
 | 
			
		||||
                sortType = new SortType(st);
 | 
			
		||||
                sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + "-", SortType.Time.ALL.name());
 | 
			
		||||
            }
 | 
			
		||||
            sortType = newSortType(sort, sortTime);
 | 
			
		||||
 | 
			
		||||
            postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout);
 | 
			
		||||
 | 
			
		||||
@@ -803,14 +791,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
 | 
			
		||||
            nameOfUsage = multiRedditPath;
 | 
			
		||||
 | 
			
		||||
            String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath, SortType.Type.HOT.name());
 | 
			
		||||
            SortType.Type st = SortType.Type.fromValue(sort);
 | 
			
		||||
            st = st == null ? SortType.Type.NEW : st;
 | 
			
		||||
            String sortTime = null;
 | 
			
		||||
            if (sort.equals(SortType.Type.TOP.name())) {
 | 
			
		||||
                String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath, SortType.Time.ALL.name());
 | 
			
		||||
                sortType = new SortType(st, SortType.Time.valueOf(sortTime));
 | 
			
		||||
            } else {
 | 
			
		||||
                sortType = new SortType(st);
 | 
			
		||||
                sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath, SortType.Time.ALL.name());
 | 
			
		||||
            }
 | 
			
		||||
            sortType = newSortType(sort, sortTime);
 | 
			
		||||
 | 
			
		||||
            postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiRedditPath, defaultPostLayout);
 | 
			
		||||
 | 
			
		||||
@@ -863,14 +848,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
 | 
			
		||||
            nameOfUsage = PostFilterUsage.NO_USAGE;
 | 
			
		||||
            subredditName = getArguments().getString(EXTRA_NAME);
 | 
			
		||||
            String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, SortType.Type.ACTIVE.name());
 | 
			
		||||
            SortType.Type st = SortType.Type.fromValue(sort);
 | 
			
		||||
            st = st == null ? SortType.Type.NEW : st;
 | 
			
		||||
            String sortTime = null;
 | 
			
		||||
            if (sort.equals(SortType.Type.TOP.name())) {
 | 
			
		||||
                String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_BEST_POST, SortType.Time.ALL.name());
 | 
			
		||||
                sortType = new SortType(st, SortType.Time.valueOf(sortTime));
 | 
			
		||||
            } else {
 | 
			
		||||
                sortType = new SortType(st);
 | 
			
		||||
                sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_BEST_POST, SortType.Time.ALL.name());
 | 
			
		||||
            }
 | 
			
		||||
            sortType = newSortType(sort, sortTime);
 | 
			
		||||
            postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout);
 | 
			
		||||
 | 
			
		||||
            mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit,
 | 
			
		||||
@@ -1221,30 +1203,36 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
 | 
			
		||||
                    mRetrofit, accessToken,
 | 
			
		||||
                    accountName, mSharedPreferences,
 | 
			
		||||
                    mPostFeedScrolledPositionSharedPreferences, mPostHistorySharedPreferences, subredditName,
 | 
			
		||||
                    query, trendingSource, postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
 | 
			
		||||
                    query, trendingSource, postType, sortType, postFilter, readPosts, postEnricher))
 | 
			
		||||
                    .get(PostViewModel.class);
 | 
			
		||||
        } else if (postType == PostPagingSource.TYPE_SUBREDDIT) {
 | 
			
		||||
            mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
 | 
			
		||||
                    mRetrofit, accessToken,
 | 
			
		||||
                    accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
 | 
			
		||||
                    mPostHistorySharedPreferences, subredditName, postType, sortType, postFilter, readPosts))
 | 
			
		||||
                    mPostHistorySharedPreferences, subredditName, postType, sortType, postFilter, readPosts,
 | 
			
		||||
                    postEnricher))
 | 
			
		||||
                    .get(PostViewModel.class);
 | 
			
		||||
        } else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) {
 | 
			
		||||
            mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
 | 
			
		||||
                    mRetrofit, accessToken,
 | 
			
		||||
                    accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
 | 
			
		||||
                    mPostHistorySharedPreferences, multiRedditPath, postType, sortType, postFilter, readPosts))
 | 
			
		||||
                    mPostHistorySharedPreferences, multiRedditPath, postType, sortType, postFilter, readPosts,
 | 
			
		||||
                    postEnricher))
 | 
			
		||||
                    .get(PostViewModel.class);
 | 
			
		||||
        } else if (postType == PostPagingSource.TYPE_USER) {
 | 
			
		||||
            mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
 | 
			
		||||
                    mRetrofit, accessToken,
 | 
			
		||||
                    accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
 | 
			
		||||
                    mPostHistorySharedPreferences, username, postType, sortType, postFilter, where, readPosts))
 | 
			
		||||
                    mPostHistorySharedPreferences, username, postType, sortType, postFilter, where, readPosts,
 | 
			
		||||
                    postEnricher))
 | 
			
		||||
                    .get(PostViewModel.class);
 | 
			
		||||
        } else {
 | 
			
		||||
            mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
 | 
			
		||||
                    mRetrofit, accessToken,
 | 
			
		||||
                    accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
 | 
			
		||||
                    mPostHistorySharedPreferences, postType, sortType, postFilter, readPosts, subredditName)).get(PostViewModel.class);
 | 
			
		||||
                    mPostHistorySharedPreferences, postType, sortType, postFilter, readPosts, subredditName,
 | 
			
		||||
                    postEnricher))
 | 
			
		||||
                    .get(PostViewModel.class);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        bindPostViewModel();
 | 
			
		||||
@@ -1256,26 +1244,27 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
 | 
			
		||||
            mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
 | 
			
		||||
                    mRetrofit, null, accountName, mSharedPreferences,
 | 
			
		||||
                    mPostFeedScrolledPositionSharedPreferences, null, subredditName, query, trendingSource,
 | 
			
		||||
                    postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
 | 
			
		||||
                    postType, sortType, postFilter, readPosts, postEnricher)).get(PostViewModel.class);
 | 
			
		||||
        } else if (postType == PostPagingSource.TYPE_SUBREDDIT) {
 | 
			
		||||
            mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(mExecutor,
 | 
			
		||||
                    mRetrofit, null, accountName, mSharedPreferences,
 | 
			
		||||
                    mPostFeedScrolledPositionSharedPreferences, null, subredditName, postType, sortType,
 | 
			
		||||
                    postFilter, readPosts)).get(PostViewModel.class);
 | 
			
		||||
                    postFilter, readPosts, postEnricher)).get(PostViewModel.class);
 | 
			
		||||
        } else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) {
 | 
			
		||||
            mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
 | 
			
		||||
                    mRetrofit, null, accountName, mSharedPreferences,
 | 
			
		||||
                    mPostFeedScrolledPositionSharedPreferences, null, multiRedditPath,
 | 
			
		||||
                    postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
 | 
			
		||||
                    postType, sortType, postFilter, readPosts, postEnricher)).get(PostViewModel.class);
 | 
			
		||||
        } else if (postType == PostPagingSource.TYPE_USER) {
 | 
			
		||||
            mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
 | 
			
		||||
                    mRetrofit, null, accountName, mSharedPreferences,
 | 
			
		||||
                    mPostFeedScrolledPositionSharedPreferences, null, username, postType, sortType, postFilter,
 | 
			
		||||
                    where, readPosts)).get(PostViewModel.class);
 | 
			
		||||
                    where, readPosts, postEnricher)).get(PostViewModel.class);
 | 
			
		||||
        } else {
 | 
			
		||||
            //Anonymous Front Page
 | 
			
		||||
            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);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -1379,25 +1368,25 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
 | 
			
		||||
            if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_SORT_TYPE, true)) {
 | 
			
		||||
                switch (postType) {
 | 
			
		||||
                    case PostPagingSource.TYPE_FRONT_PAGE:
 | 
			
		||||
                        mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, sortType.getType().name()).apply();
 | 
			
		||||
                        mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, sortType.getType().value).apply();
 | 
			
		||||
                        if (sortType.getTime() != null) {
 | 
			
		||||
                            mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_BEST_POST, sortType.getTime().name()).apply();
 | 
			
		||||
                        }
 | 
			
		||||
                        break;
 | 
			
		||||
                    case PostPagingSource.TYPE_SUBREDDIT:
 | 
			
		||||
                        mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + subredditName, sortType.getType().name()).apply();
 | 
			
		||||
                        mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + subredditName, sortType.getType().value).apply();
 | 
			
		||||
                        if (sortType.getTime() != null) {
 | 
			
		||||
                            mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + subredditName, sortType.getTime().name()).apply();
 | 
			
		||||
                        }
 | 
			
		||||
                        break;
 | 
			
		||||
                    case PostPagingSource.TYPE_USER:
 | 
			
		||||
                        mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username, sortType.getType().name()).apply();
 | 
			
		||||
                        mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username, sortType.getType().value).apply();
 | 
			
		||||
                        if (sortType.getTime() != null) {
 | 
			
		||||
                            mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username, sortType.getTime().name()).apply();
 | 
			
		||||
                        }
 | 
			
		||||
                        break;
 | 
			
		||||
                    case PostPagingSource.TYPE_SEARCH:
 | 
			
		||||
                        mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, sortType.getType().name()).apply();
 | 
			
		||||
                        mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, sortType.getType().value).apply();
 | 
			
		||||
                        if (sortType.getTime() != null) {
 | 
			
		||||
                            mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, sortType.getTime().name()).apply();
 | 
			
		||||
                        }else {
 | 
			
		||||
@@ -1407,14 +1396,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
 | 
			
		||||
                    case PostPagingSource.TYPE_MULTI_REDDIT:
 | 
			
		||||
                    case PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT:
 | 
			
		||||
                        mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath,
 | 
			
		||||
                                sortType.getType().name()).apply();
 | 
			
		||||
                                sortType.getType().value).apply();
 | 
			
		||||
                        if (sortType.getTime() != null) {
 | 
			
		||||
                            mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath,
 | 
			
		||||
                                    sortType.getTime().name()).apply();
 | 
			
		||||
                        }
 | 
			
		||||
                        break;
 | 
			
		||||
                    case PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE:
 | 
			
		||||
                        mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + "-", sortType.getType().name()).apply();
 | 
			
		||||
                        mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + "-", sortType.getType().value).apply();
 | 
			
		||||
                        if (sortType.getTime() != null) {
 | 
			
		||||
                            mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + "-", sortType.getTime().name()).apply();
 | 
			
		||||
                        }
 | 
			
		||||
@@ -2253,6 +2242,24 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public SortType newSortType(String sortTypeText, String sortTimeText) {
 | 
			
		||||
        SortType.Type st = SortType.Type.fromValue(sortTypeText);
 | 
			
		||||
        st = st == null ? SortType.Type.NEW : st;
 | 
			
		||||
        SortType result;
 | 
			
		||||
        if (sortTypeText.startsWith("Top")) {
 | 
			
		||||
            sortTimeText = st.value.substring(3);
 | 
			
		||||
            result = new SortType(st, SortType.Time.fromValue(sortTimeText));
 | 
			
		||||
        } else if (sortTimeText != null) {
 | 
			
		||||
            SortType.Time sortTime = SortType.Time.fromValue(sortTimeText);
 | 
			
		||||
            SortType.Type sortType = SortType.Type.fromValue("Top" + sortTimeText);
 | 
			
		||||
            result = new SortType(sortType != null ? sortType : st, sortTime);
 | 
			
		||||
        } else {
 | 
			
		||||
            result = new SortType(st);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static abstract class LazyModeRunnable implements Runnable {
 | 
			
		||||
        private int currentPosition = -1;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -112,6 +112,7 @@ import eu.toldi.infinityforlemmy.post.HidePost;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.LemmyPostAPI;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.MarkPostAsRead;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.Post;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
 | 
			
		||||
import eu.toldi.infinityforlemmy.readpost.InsertReadPost;
 | 
			
		||||
import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData;
 | 
			
		||||
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
 | 
			
		||||
@@ -200,6 +201,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
 | 
			
		||||
    MarkPostAsRead markPostAsRead;
 | 
			
		||||
    @Inject
 | 
			
		||||
    LemmyPostAPI mLemmyPostAPI;
 | 
			
		||||
    @Inject
 | 
			
		||||
    PostEnricher postEnricher;
 | 
			
		||||
    @State
 | 
			
		||||
    Post mPost;
 | 
			
		||||
    @State
 | 
			
		||||
@@ -324,7 +327,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
 | 
			
		||||
        mLockFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false);
 | 
			
		||||
        mSwipeUpToHideFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_UP_TO_HIDE_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false);
 | 
			
		||||
        mExpandChildren = !mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_TOP_LEVEL_COMMENTS_FIRST, false);
 | 
			
		||||
        mMarkPostsAsRead = mPostHistorySharedPreferences.getBoolean(mAccountQualifiedName + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false);
 | 
			
		||||
        mMarkPostsAsRead = mPostHistorySharedPreferences.getBoolean(mAccountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false);
 | 
			
		||||
        if (savedInstanceState == null) {
 | 
			
		||||
            mRespectSubredditRecommendedSortType = mSharedPreferences.getBoolean(SharedPreferencesUtils.RESPECT_SUBREDDIT_RECOMMENDED_COMMENT_SORT_TYPE, false);
 | 
			
		||||
            viewPostDetailFragmentId = System.currentTimeMillis();
 | 
			
		||||
@@ -1329,7 +1332,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
 | 
			
		||||
        mSwipeRefreshLayout.setRefreshing(true);
 | 
			
		||||
        mGlide.clear(mFetchPostInfoImageView);
 | 
			
		||||
        FetchPost.fetchPost(mExecutor, new Handler(), mRetrofit.getRetrofit(), String.valueOf(subredditId), mAccessToken,
 | 
			
		||||
                new FetchPost.FetchPostListener() {
 | 
			
		||||
                postEnricher, new FetchPost.FetchPostListener() {
 | 
			
		||||
                    @Override
 | 
			
		||||
                    public void fetchPostSuccess(Post post) {
 | 
			
		||||
                        if (!isAdded()) {
 | 
			
		||||
@@ -1588,7 +1591,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
 | 
			
		||||
                Retrofit retrofit = mRetrofit.getRetrofit();
 | 
			
		||||
 | 
			
		||||
                FetchPost.fetchPost(mExecutor, new Handler(), retrofit, String.valueOf(mPost.getId()), mAccessToken,
 | 
			
		||||
                        new FetchPost.FetchPostListener() {
 | 
			
		||||
                        postEnricher, new FetchPost.FetchPostListener() {
 | 
			
		||||
                            @Override
 | 
			
		||||
                            public void fetchPostSuccess(Post post) {
 | 
			
		||||
                                if (isAdded()) {
 | 
			
		||||
 
 | 
			
		||||
@@ -52,6 +52,7 @@ import java.io.File;
 | 
			
		||||
import java.util.concurrent.Executor;
 | 
			
		||||
 | 
			
		||||
import javax.inject.Inject;
 | 
			
		||||
import javax.inject.Named;
 | 
			
		||||
 | 
			
		||||
import butterknife.BindView;
 | 
			
		||||
import butterknife.ButterKnife;
 | 
			
		||||
@@ -69,6 +70,7 @@ import eu.toldi.infinityforlemmy.bottomsheetfragments.UrlMenuBottomSheetFragment
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.Post;
 | 
			
		||||
import eu.toldi.infinityforlemmy.services.DownloadMediaService;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.Utils;
 | 
			
		||||
import okhttp3.OkHttpClient;
 | 
			
		||||
 | 
			
		||||
public class ViewRedditGalleryImageOrGifFragment extends Fragment {
 | 
			
		||||
 | 
			
		||||
@@ -105,6 +107,9 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
 | 
			
		||||
    ImageView wallpaperImageView;
 | 
			
		||||
    @Inject
 | 
			
		||||
    Executor mExecutor;
 | 
			
		||||
    @Inject
 | 
			
		||||
    @Named("glide")
 | 
			
		||||
    OkHttpClient okHttpClient;
 | 
			
		||||
 | 
			
		||||
    private ViewRedditGalleryActivity activity;
 | 
			
		||||
    private RequestManager glide;
 | 
			
		||||
@@ -122,7 +127,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
 | 
			
		||||
    @Override
 | 
			
		||||
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
 | 
			
		||||
                             Bundle savedInstanceState) {
 | 
			
		||||
        BigImageViewer.initialize(GlideImageLoader.with(activity.getApplicationContext()));
 | 
			
		||||
        BigImageViewer.initialize(GlideImageLoader.with(activity.getApplicationContext(), okHttpClient));
 | 
			
		||||
 | 
			
		||||
        View rootView = inflater.inflate(R.layout.fragment_view_reddit_gallery_image_or_gif, container, false);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,7 @@ import java.util.concurrent.Executor;
 | 
			
		||||
 | 
			
		||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
 | 
			
		||||
import eu.toldi.infinityforlemmy.apis.RedditAPI;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
 | 
			
		||||
import retrofit2.Call;
 | 
			
		||||
import retrofit2.Callback;
 | 
			
		||||
import retrofit2.Response;
 | 
			
		||||
@@ -15,7 +16,7 @@ import retrofit2.Retrofit;
 | 
			
		||||
 | 
			
		||||
public class FetchPost {
 | 
			
		||||
    public static void fetchPost(Executor executor, Handler handler, Retrofit retrofit, String id, String accessToken,
 | 
			
		||||
                                 FetchPostListener fetchPostListener) {
 | 
			
		||||
                                 PostEnricher postEnricher, FetchPostListener fetchPostListener) {
 | 
			
		||||
        Call<String> postCall;
 | 
			
		||||
        // Use LemmyAPI.postInfo() instead of RedditAPI.getPost()
 | 
			
		||||
        postCall = retrofit.create(LemmyAPI.class).postInfo(Integer.parseInt(id), null, accessToken);
 | 
			
		||||
@@ -24,7 +25,7 @@ public class FetchPost {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
 | 
			
		||||
                if (response.isSuccessful()) {
 | 
			
		||||
                    ParsePost.parsePost(executor, handler, response.body(), new ParsePost.ParsePostListener() {
 | 
			
		||||
                    ParsePost.parsePost(executor, handler, postEnricher, response.body(), new ParsePost.ParsePostListener() {
 | 
			
		||||
                        @Override
 | 
			
		||||
                        public void onParsePostSuccess(Post post) {
 | 
			
		||||
                            fetchPostListener.fetchPostSuccess(post);
 | 
			
		||||
 
 | 
			
		||||
@@ -19,6 +19,7 @@ import java.util.concurrent.Executor;
 | 
			
		||||
 | 
			
		||||
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
 | 
			
		||||
import eu.toldi.infinityforlemmy.apis.RedditAPI;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
 | 
			
		||||
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
 | 
			
		||||
import eu.toldi.infinityforlemmy.readpost.ReadPost;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
 | 
			
		||||
@@ -39,10 +40,11 @@ public class HistoryPostPagingSource extends ListenableFuturePagingSource<String
 | 
			
		||||
    private String username;
 | 
			
		||||
    private int postType;
 | 
			
		||||
    private PostFilter postFilter;
 | 
			
		||||
    private PostEnricher postEnricher;
 | 
			
		||||
 | 
			
		||||
    public HistoryPostPagingSource(Retrofit retrofit, Executor executor, RedditDataRoomDatabase redditDataRoomDatabase,
 | 
			
		||||
                                   String accessToken, String accountName, SharedPreferences sharedPreferences,
 | 
			
		||||
                                   String username, int postType, PostFilter postFilter) {
 | 
			
		||||
                                   String username, int postType, PostFilter postFilter, PostEnricher postEnricher) {
 | 
			
		||||
        this.retrofit = retrofit;
 | 
			
		||||
        this.executor = executor;
 | 
			
		||||
        this.redditDataRoomDatabase = redditDataRoomDatabase;
 | 
			
		||||
@@ -52,6 +54,7 @@ public class HistoryPostPagingSource extends ListenableFuturePagingSource<String
 | 
			
		||||
        this.username = username;
 | 
			
		||||
        this.postType = postType;
 | 
			
		||||
        this.postFilter = postFilter;
 | 
			
		||||
        this.postEnricher = postEnricher;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nullable
 | 
			
		||||
@@ -92,7 +95,7 @@ public class HistoryPostPagingSource extends ListenableFuturePagingSource<String
 | 
			
		||||
            Response<String> response = historyPosts.execute();
 | 
			
		||||
            if (response.isSuccessful()) {
 | 
			
		||||
                String responseString = response.body();
 | 
			
		||||
                LinkedHashSet<Post> newPosts = ParsePost.parsePostsSync(responseString, -1, postFilter, null);
 | 
			
		||||
                LinkedHashSet<Post> newPosts = ParsePost.parsePostsSync(responseString, -1, postFilter, null, postEnricher);
 | 
			
		||||
                if (newPosts == null) {
 | 
			
		||||
                    return new LoadResult.Error<>(new Exception("Error parsing posts"));
 | 
			
		||||
                } else {
 | 
			
		||||
 
 | 
			
		||||
@@ -17,6 +17,7 @@ import androidx.paging.PagingLiveData;
 | 
			
		||||
import java.util.concurrent.Executor;
 | 
			
		||||
 | 
			
		||||
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
 | 
			
		||||
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
 | 
			
		||||
import retrofit2.Retrofit;
 | 
			
		||||
 | 
			
		||||
@@ -29,6 +30,7 @@ public class HistoryPostViewModel extends ViewModel {
 | 
			
		||||
    private SharedPreferences sharedPreferences;
 | 
			
		||||
    private int postType;
 | 
			
		||||
    private PostFilter postFilter;
 | 
			
		||||
    private PostEnricher postEnricher;
 | 
			
		||||
 | 
			
		||||
    private LiveData<PagingData<Post>> posts;
 | 
			
		||||
 | 
			
		||||
@@ -36,7 +38,7 @@ public class HistoryPostViewModel extends ViewModel {
 | 
			
		||||
 | 
			
		||||
    public HistoryPostViewModel(Executor executor, Retrofit retrofit, RedditDataRoomDatabase redditDataRoomDatabase,
 | 
			
		||||
                                String accessToken, String accountName, SharedPreferences sharedPreferences,
 | 
			
		||||
                                int postType, PostFilter postFilter) {
 | 
			
		||||
                                int postType, PostFilter postFilter, PostEnricher postEnricher) {
 | 
			
		||||
        this.executor = executor;
 | 
			
		||||
        this.retrofit = retrofit;
 | 
			
		||||
        this.redditDataRoomDatabase = redditDataRoomDatabase;
 | 
			
		||||
@@ -45,11 +47,12 @@ public class HistoryPostViewModel extends ViewModel {
 | 
			
		||||
        this.sharedPreferences = sharedPreferences;
 | 
			
		||||
        this.postType = postType;
 | 
			
		||||
        this.postFilter = postFilter;
 | 
			
		||||
        this.postEnricher = postEnricher;
 | 
			
		||||
 | 
			
		||||
        postFilterLiveData = new MutableLiveData<>();
 | 
			
		||||
        postFilterLiveData.postValue(postFilter);
 | 
			
		||||
 | 
			
		||||
        Pager<String, Post> pager = new Pager<>(new PagingConfig(25, 25, false), this::returnPagingSoruce);
 | 
			
		||||
        Pager<String, Post> pager = new Pager<>(new PagingConfig(25, 25, false), this::returnPagingSource);
 | 
			
		||||
 | 
			
		||||
        posts = Transformations.switchMap(postFilterLiveData, postFilterValue -> PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this)));
 | 
			
		||||
    }
 | 
			
		||||
@@ -58,19 +61,9 @@ public class HistoryPostViewModel extends ViewModel {
 | 
			
		||||
        return posts;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public HistoryPostPagingSource returnPagingSoruce() {
 | 
			
		||||
        HistoryPostPagingSource paging3PagingSource;
 | 
			
		||||
        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 HistoryPostPagingSource returnPagingSource() {
 | 
			
		||||
        return new HistoryPostPagingSource(retrofit, executor, redditDataRoomDatabase, accessToken, accountName,
 | 
			
		||||
                sharedPreferences, accountName, postType, postFilter, postEnricher);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void changePostFilter(PostFilter postFilter) {
 | 
			
		||||
@@ -86,10 +79,11 @@ public class HistoryPostViewModel extends ViewModel {
 | 
			
		||||
        private SharedPreferences sharedPreferences;
 | 
			
		||||
        private int postType;
 | 
			
		||||
        private PostFilter postFilter;
 | 
			
		||||
        private PostEnricher postEnricher;
 | 
			
		||||
 | 
			
		||||
        public Factory(Executor executor, Retrofit retrofit, RedditDataRoomDatabase redditDataRoomDatabase,
 | 
			
		||||
                       String accessToken, String accountName, SharedPreferences sharedPreferences, int postType,
 | 
			
		||||
                       PostFilter postFilter) {
 | 
			
		||||
                       PostFilter postFilter, PostEnricher postEnricher) {
 | 
			
		||||
            this.executor = executor;
 | 
			
		||||
            this.retrofit = retrofit;
 | 
			
		||||
            this.redditDataRoomDatabase = redditDataRoomDatabase;
 | 
			
		||||
@@ -98,18 +92,14 @@ public class HistoryPostViewModel extends ViewModel {
 | 
			
		||||
            this.sharedPreferences = sharedPreferences;
 | 
			
		||||
            this.postType = postType;
 | 
			
		||||
            this.postFilter = postFilter;
 | 
			
		||||
            this.postEnricher = postEnricher;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @NonNull
 | 
			
		||||
        @Override
 | 
			
		||||
        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,
 | 
			
		||||
                        postType, postFilter);
 | 
			
		||||
            } else {
 | 
			
		||||
                return (T) new HistoryPostViewModel(executor, retrofit, redditDataRoomDatabase, accessToken, accountName, sharedPreferences,
 | 
			
		||||
                        postType, postFilter);
 | 
			
		||||
            }
 | 
			
		||||
            return (T) new HistoryPostViewModel(executor, retrofit, redditDataRoomDatabase, accessToken, accountName, sharedPreferences,
 | 
			
		||||
                        postType, postFilter, postEnricher);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -34,6 +34,7 @@ import java.util.regex.Matcher;
 | 
			
		||||
import java.util.regex.Pattern;
 | 
			
		||||
 | 
			
		||||
import eu.toldi.infinityforlemmy.community.BasicCommunityInfo;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
 | 
			
		||||
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
 | 
			
		||||
import eu.toldi.infinityforlemmy.user.BasicUserInfo;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.JSONUtils;
 | 
			
		||||
@@ -45,7 +46,8 @@ import eu.toldi.infinityforlemmy.utils.Utils;
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class ParsePost {
 | 
			
		||||
    public static LinkedHashSet<Post> parsePostsSync(String response, int nPosts, PostFilter postFilter, List<String> readPostList) {
 | 
			
		||||
    public static LinkedHashSet<Post> parsePostsSync(String response, int nPosts, PostFilter postFilter,
 | 
			
		||||
                                                     List<String> readPostList, PostEnricher postEnricher) {
 | 
			
		||||
        LinkedHashSet<Post> newPosts = new LinkedHashSet<>();
 | 
			
		||||
        try {
 | 
			
		||||
            JSONObject jsonResponse = new JSONObject(response);
 | 
			
		||||
@@ -80,6 +82,8 @@ public class ParsePost {
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            postEnricher.enrich(newPosts);
 | 
			
		||||
 | 
			
		||||
            return newPosts;
 | 
			
		||||
        } catch (JSONException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
@@ -87,21 +91,9 @@ public class ParsePost {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static String getLastItem(String response) {
 | 
			
		||||
        try {
 | 
			
		||||
            JSONObject object = new JSONObject(response).getJSONObject(JSONUtils.DATA_KEY);
 | 
			
		||||
            return object.isNull(JSONUtils.AFTER_KEY) ? null : object.getString(JSONUtils.AFTER_KEY);
 | 
			
		||||
        } catch (JSONException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public static void parsePost(Executor executor, Handler handler, String response, ParsePostListener parsePostListener) {
 | 
			
		||||
        PostFilter postFilter = new PostFilter();
 | 
			
		||||
        postFilter.allowNSFW = true;
 | 
			
		||||
 | 
			
		||||
    public static void parsePost(Executor executor, Handler handler, PostEnricher postEnricher,
 | 
			
		||||
                                 String response, ParsePostListener parsePostListener) {
 | 
			
		||||
        executor.execute(() -> {
 | 
			
		||||
            try {
 | 
			
		||||
                JSONObject allData = new JSONObject(response).getJSONObject("post_view");
 | 
			
		||||
@@ -111,6 +103,7 @@ public class ParsePost {
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                Post post = parseBasicData(allData);
 | 
			
		||||
                postEnricher.enrich(List.of(post));
 | 
			
		||||
                handler.post(() -> parsePostListener.onParsePostSuccess(post));
 | 
			
		||||
            } catch (JSONException e) {
 | 
			
		||||
                e.printStackTrace();
 | 
			
		||||
@@ -188,7 +181,7 @@ public class ParsePost {
 | 
			
		||||
        boolean nsfw = post.getBoolean("nsfw");
 | 
			
		||||
        boolean locked = post.getBoolean("locked");
 | 
			
		||||
        boolean saved = data.getBoolean("saved");
 | 
			
		||||
        String distinguished = (creator.getBoolean("admin") ? "admin" : "");
 | 
			
		||||
        String distinguished = creator.optBoolean("admin") ? "admin" : "";
 | 
			
		||||
        String suggestedSort = "";
 | 
			
		||||
        ArrayList<Post.Preview> previews = new ArrayList<>();
 | 
			
		||||
        if (!post.isNull("thumbnail_url")) {
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,7 @@ import java.util.concurrent.Executor;
 | 
			
		||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
 | 
			
		||||
import eu.toldi.infinityforlemmy.SortType;
 | 
			
		||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
 | 
			
		||||
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
 | 
			
		||||
import retrofit2.HttpException;
 | 
			
		||||
@@ -57,6 +58,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
 | 
			
		||||
    private List<String> readPostList;
 | 
			
		||||
    private String userWhere;
 | 
			
		||||
    private String multiRedditPath;
 | 
			
		||||
    private final PostEnricher postEnricher;
 | 
			
		||||
    private LinkedHashSet<Post> postLinkedHashSet;
 | 
			
		||||
 | 
			
		||||
    private int page = 1;
 | 
			
		||||
@@ -64,7 +66,8 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
 | 
			
		||||
    PostPagingSource(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
 | 
			
		||||
                     SharedPreferences sharedPreferences,
 | 
			
		||||
                     SharedPreferences postFeedScrolledPositionSharedPreferences, int postType,
 | 
			
		||||
                     SortType sortType, PostFilter postFilter, List<String> readPostList, String option) {
 | 
			
		||||
                     SortType sortType, PostFilter postFilter, List<String> readPostList, String option,
 | 
			
		||||
                     PostEnricher postEnricher) {
 | 
			
		||||
        this.executor = executor;
 | 
			
		||||
        this.retrofit = retrofit;
 | 
			
		||||
        this.accessToken = accessToken;
 | 
			
		||||
@@ -76,13 +79,14 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
 | 
			
		||||
        this.sortType = sortType == null ? new SortType(SortType.Type.ACTIVE) : sortType;
 | 
			
		||||
        this.postFilter = postFilter;
 | 
			
		||||
        this.readPostList = readPostList;
 | 
			
		||||
        this.postEnricher = postEnricher;
 | 
			
		||||
        postLinkedHashSet = new LinkedHashSet<>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    PostPagingSource(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
 | 
			
		||||
                     SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
 | 
			
		||||
                     String path, int postType, SortType sortType, PostFilter postFilter,
 | 
			
		||||
                     List<String> readPostList) {
 | 
			
		||||
                     List<String> readPostList, PostEnricher postEnricher) {
 | 
			
		||||
        this.executor = executor;
 | 
			
		||||
        this.retrofit = retrofit;
 | 
			
		||||
        this.accessToken = accessToken;
 | 
			
		||||
@@ -114,13 +118,14 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
 | 
			
		||||
        }
 | 
			
		||||
        this.postFilter = postFilter;
 | 
			
		||||
        this.readPostList = readPostList;
 | 
			
		||||
        this.postEnricher = postEnricher;
 | 
			
		||||
        postLinkedHashSet = new LinkedHashSet<>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    PostPagingSource(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
 | 
			
		||||
                     SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
 | 
			
		||||
                     String subredditOrUserName, int postType, SortType sortType, PostFilter postFilter,
 | 
			
		||||
                     String where, List<String> readPostList) {
 | 
			
		||||
                     String where, List<String> readPostList, PostEnricher postEnricher) {
 | 
			
		||||
        this.executor = executor;
 | 
			
		||||
        this.retrofit = retrofit;
 | 
			
		||||
        this.accessToken = accessToken;
 | 
			
		||||
@@ -133,13 +138,14 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
 | 
			
		||||
        this.postFilter = postFilter;
 | 
			
		||||
        userWhere = where;
 | 
			
		||||
        this.readPostList = readPostList;
 | 
			
		||||
        this.postEnricher = postEnricher;
 | 
			
		||||
        postLinkedHashSet = new LinkedHashSet<>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    PostPagingSource(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
 | 
			
		||||
                     SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
 | 
			
		||||
                     String subredditOrUserName, String query, String trendingSource, int postType,
 | 
			
		||||
                     SortType sortType, PostFilter postFilter, List<String> readPostList) {
 | 
			
		||||
                     SortType sortType, PostFilter postFilter, List<String> readPostList, PostEnricher postEnricher) {
 | 
			
		||||
        this.executor = executor;
 | 
			
		||||
        this.retrofit = retrofit;
 | 
			
		||||
        this.accessToken = accessToken;
 | 
			
		||||
@@ -152,8 +158,9 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
 | 
			
		||||
        this.postType = postType;
 | 
			
		||||
        this.sortType = sortType == null ? new SortType(SortType.Type.TOP) : sortType;
 | 
			
		||||
        this.postFilter = postFilter;
 | 
			
		||||
        postLinkedHashSet = new LinkedHashSet<>();
 | 
			
		||||
        this.readPostList = readPostList;
 | 
			
		||||
        this.postEnricher = postEnricher;
 | 
			
		||||
        postLinkedHashSet = new LinkedHashSet<>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nullable
 | 
			
		||||
@@ -190,7 +197,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
 | 
			
		||||
    public LoadResult<Integer, Post> transformData(Response<String> response) {
 | 
			
		||||
        if (response.isSuccessful()) {
 | 
			
		||||
            String responseString = response.body();
 | 
			
		||||
            LinkedHashSet<Post> newPosts = ParsePost.parsePostsSync(responseString, -1, postFilter, readPostList);
 | 
			
		||||
            LinkedHashSet<Post> newPosts = ParsePost.parsePostsSync(responseString, -1, postFilter, readPostList, postEnricher);
 | 
			
		||||
 | 
			
		||||
            if (newPosts == null) {
 | 
			
		||||
                return new LoadResult.Error<>(new Exception("Error parsing posts"));
 | 
			
		||||
@@ -236,7 +243,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
 | 
			
		||||
        }
 | 
			
		||||
        String feed_type = Objects.equals(subredditOrUserName, "all") ? "All" : Objects.equals(subredditOrUserName, "local") ? "Local" : "Subscribed";
 | 
			
		||||
 | 
			
		||||
        bestPost = api.getPosts(feed_type,sortType.getType().value,page,25,null,null,false,accessToken);
 | 
			
		||||
        bestPost = api.getPostsListenableFuture(feed_type, sortType.getType().value, page, 25, null, null, false, accessToken);
 | 
			
		||||
 | 
			
		||||
        ListenableFuture<LoadResult<Integer, Post>> pageFuture = Futures.transform(bestPost, this::transformData, executor);
 | 
			
		||||
 | 
			
		||||
@@ -251,7 +258,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
 | 
			
		||||
    private ListenableFuture<LoadResult<Integer, Post>> loadSubredditPosts(@NonNull LoadParams<Integer> loadParams, LemmyAPI api) {
 | 
			
		||||
        ListenableFuture<Response<String>> subredditPost;
 | 
			
		||||
 | 
			
		||||
        subredditPost = api.getPosts(null,sortType.getType().value,loadParams.getKey(),25,null,subredditOrUserName,false,accessToken);
 | 
			
		||||
        subredditPost = api.getPostsListenableFuture(null, sortType.getType().value, loadParams.getKey(), 25, null, subredditOrUserName, false, accessToken);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        ListenableFuture<LoadResult<Integer, Post>> pageFuture = Futures.transform(subredditPost, this::transformData, executor);
 | 
			
		||||
@@ -266,7 +273,7 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
 | 
			
		||||
 | 
			
		||||
    private ListenableFuture<LoadResult<Integer, Post>> loadUserPosts(@NonNull LoadParams<Integer> loadParams, LemmyAPI api) {
 | 
			
		||||
        ListenableFuture<Response<String>> userPosts;
 | 
			
		||||
        userPosts = api.getUserPosts(subredditOrUserName, sortType.getType().value, loadParams.getKey(), 25, userWhere.equals(USER_WHERE_SAVED), accessToken);
 | 
			
		||||
        userPosts = api.getUserPostsListenableFuture(subredditOrUserName, sortType.getType().value, loadParams.getKey(), 25, userWhere.equals(USER_WHERE_SAVED), accessToken);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        ListenableFuture<LoadResult<Integer, Post>> pageFuture = Futures.transform(userPosts, this::transformData, executor);
 | 
			
		||||
 
 | 
			
		||||
@@ -23,6 +23,7 @@ import java.util.concurrent.Executor;
 | 
			
		||||
 | 
			
		||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
 | 
			
		||||
import eu.toldi.infinityforlemmy.SortType;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
 | 
			
		||||
import eu.toldi.infinityforlemmy.postfilter.PostFilter;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
 | 
			
		||||
 | 
			
		||||
@@ -41,6 +42,7 @@ public class PostViewModel extends ViewModel {
 | 
			
		||||
    private PostFilter postFilter;
 | 
			
		||||
    private String userWhere;
 | 
			
		||||
    private List<String> readPostList;
 | 
			
		||||
    private PostEnricher postEnricher;
 | 
			
		||||
    private MutableLiveData<Boolean> currentlyReadPostIdsLiveData = new MutableLiveData<>();
 | 
			
		||||
 | 
			
		||||
    private LiveData<PagingData<Post>> posts;
 | 
			
		||||
@@ -53,7 +55,7 @@ public class PostViewModel extends ViewModel {
 | 
			
		||||
    public PostViewModel(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
 | 
			
		||||
                         SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
 | 
			
		||||
                         @Nullable SharedPreferences postHistorySharedPreferences, int postType,
 | 
			
		||||
                         SortType sortType, PostFilter postFilter, List<String> readPostList, String option) {
 | 
			
		||||
                         SortType sortType, PostFilter postFilter, List<String> readPostList, String option, PostEnricher postEnricher) {
 | 
			
		||||
        this.executor = executor;
 | 
			
		||||
        this.retrofit = retrofit;
 | 
			
		||||
        this.accessToken = accessToken;
 | 
			
		||||
@@ -65,6 +67,7 @@ public class PostViewModel extends ViewModel {
 | 
			
		||||
        this.postFilter = postFilter;
 | 
			
		||||
        this.readPostList = readPostList;
 | 
			
		||||
        this.name = option;
 | 
			
		||||
        this.postEnricher = postEnricher;
 | 
			
		||||
 | 
			
		||||
        sortTypeLiveData = new MutableLiveData<>();
 | 
			
		||||
        sortTypeLiveData.postValue(sortType);
 | 
			
		||||
@@ -95,7 +98,7 @@ public class PostViewModel extends ViewModel {
 | 
			
		||||
    public PostViewModel(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
 | 
			
		||||
                         SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
 | 
			
		||||
                         @Nullable SharedPreferences postHistorySharedPreferences, String subredditName, int postType,
 | 
			
		||||
                         SortType sortType, PostFilter postFilter, List<String> readPostList) {
 | 
			
		||||
                         SortType sortType, PostFilter postFilter, List<String> readPostList, PostEnricher postEnricher) {
 | 
			
		||||
        this.executor = executor;
 | 
			
		||||
        this.retrofit = retrofit;
 | 
			
		||||
        this.accessToken = accessToken;
 | 
			
		||||
@@ -107,6 +110,7 @@ public class PostViewModel extends ViewModel {
 | 
			
		||||
        this.postFilter = postFilter;
 | 
			
		||||
        this.readPostList = readPostList;
 | 
			
		||||
        this.name = subredditName;
 | 
			
		||||
        this.postEnricher = postEnricher;
 | 
			
		||||
 | 
			
		||||
        sortTypeLiveData = new MutableLiveData<>();
 | 
			
		||||
        sortTypeLiveData.postValue(sortType);
 | 
			
		||||
@@ -139,7 +143,7 @@ public class PostViewModel extends ViewModel {
 | 
			
		||||
                         SharedPreferences postFeedScrolledPositionSharedPreferences,
 | 
			
		||||
                         @Nullable SharedPreferences postHistorySharedPreferences, String username,
 | 
			
		||||
                         int postType, SortType sortType, PostFilter postFilter, String userWhere,
 | 
			
		||||
                         List<String> readPostList) {
 | 
			
		||||
                         List<String> readPostList, PostEnricher postEnricher) {
 | 
			
		||||
        this.executor = executor;
 | 
			
		||||
        this.retrofit = retrofit;
 | 
			
		||||
        this.accessToken = accessToken;
 | 
			
		||||
@@ -152,6 +156,7 @@ public class PostViewModel extends ViewModel {
 | 
			
		||||
        this.readPostList = readPostList;
 | 
			
		||||
        this.name = username;
 | 
			
		||||
        this.userWhere = userWhere;
 | 
			
		||||
        this.postEnricher = postEnricher;
 | 
			
		||||
 | 
			
		||||
        sortTypeLiveData = new MutableLiveData<>();
 | 
			
		||||
        sortTypeLiveData.postValue(sortType);
 | 
			
		||||
@@ -183,7 +188,7 @@ public class PostViewModel extends ViewModel {
 | 
			
		||||
                         SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
 | 
			
		||||
                         @Nullable SharedPreferences postHistorySharedPreferences, String subredditName, String query,
 | 
			
		||||
                         String trendingSource, int postType, SortType sortType, PostFilter postFilter,
 | 
			
		||||
                         List<String> readPostList) {
 | 
			
		||||
                         List<String> readPostList, PostEnricher postEnricher) {
 | 
			
		||||
        this.executor = executor;
 | 
			
		||||
        this.retrofit = retrofit;
 | 
			
		||||
        this.accessToken = accessToken;
 | 
			
		||||
@@ -197,6 +202,7 @@ public class PostViewModel extends ViewModel {
 | 
			
		||||
        this.name = subredditName;
 | 
			
		||||
        this.query = query;
 | 
			
		||||
        this.trendingSource = trendingSource;
 | 
			
		||||
        this.postEnricher = postEnricher;
 | 
			
		||||
 | 
			
		||||
        sortTypeLiveData = new MutableLiveData<>();
 | 
			
		||||
        sortTypeLiveData.postValue(sortType);
 | 
			
		||||
@@ -238,25 +244,25 @@ public class PostViewModel extends ViewModel {
 | 
			
		||||
            case PostPagingSource.TYPE_FRONT_PAGE:
 | 
			
		||||
                paging3PagingSource = new PostPagingSource(executor, retrofit, accessToken, accountName,
 | 
			
		||||
                        sharedPreferences, postFeedScrolledPositionSharedPreferences, postType, sortType,
 | 
			
		||||
                        postFilter, readPostList,name);
 | 
			
		||||
                        postFilter, readPostList, name, postEnricher);
 | 
			
		||||
                break;
 | 
			
		||||
            case PostPagingSource.TYPE_SUBREDDIT:
 | 
			
		||||
            case PostPagingSource.TYPE_MULTI_REDDIT:
 | 
			
		||||
            case PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE:
 | 
			
		||||
                paging3PagingSource = new PostPagingSource(executor, retrofit, accessToken, accountName,
 | 
			
		||||
                        sharedPreferences, postFeedScrolledPositionSharedPreferences, name, postType,
 | 
			
		||||
                        sortType, postFilter, readPostList);
 | 
			
		||||
                        sortType, postFilter, readPostList, postEnricher);
 | 
			
		||||
                break;
 | 
			
		||||
            case PostPagingSource.TYPE_SEARCH:
 | 
			
		||||
                paging3PagingSource = new PostPagingSource(executor, retrofit, accessToken, accountName,
 | 
			
		||||
                        sharedPreferences, postFeedScrolledPositionSharedPreferences, name, query, trendingSource,
 | 
			
		||||
                        postType, sortType, postFilter, readPostList);
 | 
			
		||||
                        postType, sortType, postFilter, readPostList, postEnricher);
 | 
			
		||||
                break;
 | 
			
		||||
            default:
 | 
			
		||||
                //User
 | 
			
		||||
                paging3PagingSource = new PostPagingSource(executor, retrofit, accessToken, accountName,
 | 
			
		||||
                        sharedPreferences, postFeedScrolledPositionSharedPreferences, name, postType,
 | 
			
		||||
                        sortType, postFilter, userWhere, readPostList);
 | 
			
		||||
                        sortType, postFilter, userWhere, readPostList, postEnricher);
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
        return paging3PagingSource;
 | 
			
		||||
@@ -291,11 +297,12 @@ public class PostViewModel extends ViewModel {
 | 
			
		||||
        private PostFilter postFilter;
 | 
			
		||||
        private String userWhere;
 | 
			
		||||
        private List<String> readPostList;
 | 
			
		||||
        private PostEnricher postEnricher;
 | 
			
		||||
 | 
			
		||||
        public Factory(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
 | 
			
		||||
                       SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
 | 
			
		||||
                       SharedPreferences postHistorySharedPreferences, int postType, SortType sortType,
 | 
			
		||||
                       PostFilter postFilter, List<String> readPostList, String option) {
 | 
			
		||||
                       PostFilter postFilter, List<String> readPostList, String option, PostEnricher postEnricher) {
 | 
			
		||||
            this.executor = executor;
 | 
			
		||||
            this.retrofit = retrofit;
 | 
			
		||||
            this.accessToken = accessToken;
 | 
			
		||||
@@ -308,12 +315,13 @@ public class PostViewModel extends ViewModel {
 | 
			
		||||
            this.postFilter = postFilter;
 | 
			
		||||
            this.readPostList = readPostList;
 | 
			
		||||
            this.name = option;
 | 
			
		||||
            this.postEnricher = postEnricher;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public Factory(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
 | 
			
		||||
                       SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
 | 
			
		||||
                       SharedPreferences postHistorySharedPreferences, String name, int postType, SortType sortType,
 | 
			
		||||
                       PostFilter postFilter, List<String> readPostList) {
 | 
			
		||||
                       PostFilter postFilter, List<String> readPostList, PostEnricher postEnricher) {
 | 
			
		||||
            this.executor = executor;
 | 
			
		||||
            this.retrofit = retrofit;
 | 
			
		||||
            this.accessToken = accessToken;
 | 
			
		||||
@@ -326,13 +334,15 @@ public class PostViewModel extends ViewModel {
 | 
			
		||||
            this.sortType = sortType;
 | 
			
		||||
            this.postFilter = postFilter;
 | 
			
		||||
            this.readPostList = readPostList;
 | 
			
		||||
            this.postEnricher = postEnricher;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //User posts
 | 
			
		||||
        public Factory(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
 | 
			
		||||
                       SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
 | 
			
		||||
                       SharedPreferences postHistorySharedPreferences, String username, int postType,
 | 
			
		||||
                       SortType sortType, PostFilter postFilter, String where, List<String> readPostList) {
 | 
			
		||||
                       SortType sortType, PostFilter postFilter, String where, List<String> readPostList,
 | 
			
		||||
                       PostEnricher postEnricher) {
 | 
			
		||||
            this.executor = executor;
 | 
			
		||||
            this.retrofit = retrofit;
 | 
			
		||||
            this.accessToken = accessToken;
 | 
			
		||||
@@ -346,12 +356,14 @@ public class PostViewModel extends ViewModel {
 | 
			
		||||
            this.postFilter = postFilter;
 | 
			
		||||
            userWhere = where;
 | 
			
		||||
            this.readPostList = readPostList;
 | 
			
		||||
            this.postEnricher = postEnricher;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public Factory(Executor executor, RetrofitHolder retrofit, String accessToken, String accountName,
 | 
			
		||||
                       SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
 | 
			
		||||
                       SharedPreferences postHistorySharedPreferences, String name, String query, String trendingSource,
 | 
			
		||||
                       int postType, SortType sortType, PostFilter postFilter, List<String> readPostList) {
 | 
			
		||||
                       int postType, SortType sortType, PostFilter postFilter, List<String> readPostList,
 | 
			
		||||
                       PostEnricher postEnricher) {
 | 
			
		||||
            this.executor = executor;
 | 
			
		||||
            this.retrofit = retrofit;
 | 
			
		||||
            this.accessToken = accessToken;
 | 
			
		||||
@@ -366,19 +378,23 @@ public class PostViewModel extends ViewModel {
 | 
			
		||||
            this.sortType = sortType;
 | 
			
		||||
            this.postFilter = postFilter;
 | 
			
		||||
            this.readPostList = readPostList;
 | 
			
		||||
            this.postEnricher = postEnricher;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //Anonymous Front Page
 | 
			
		||||
        public Factory(Executor executor, RetrofitHolder retrofit, SharedPreferences sharedPreferences,
 | 
			
		||||
                       String concatenatedSubredditNames, int postType, SortType sortType, PostFilter postFilter, String opt) {
 | 
			
		||||
                       String concatenatedSubredditNames, int postType, SortType sortType, PostFilter postFilter,
 | 
			
		||||
                       String opt, PostEnricher postEnricher) {
 | 
			
		||||
            this.executor = executor;
 | 
			
		||||
            this.retrofit = retrofit;
 | 
			
		||||
            this.sharedPreferences = sharedPreferences;
 | 
			
		||||
            // TODO is this used? because it is getting overwritten with opt
 | 
			
		||||
            this.name = concatenatedSubredditNames;
 | 
			
		||||
            this.postType = postType;
 | 
			
		||||
            this.sortType = sortType;
 | 
			
		||||
            this.postFilter = postFilter;
 | 
			
		||||
            this.name = opt;
 | 
			
		||||
            this.postEnricher = postEnricher;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @NonNull
 | 
			
		||||
@@ -387,23 +403,23 @@ public class PostViewModel extends ViewModel {
 | 
			
		||||
            if (postType == PostPagingSource.TYPE_FRONT_PAGE) {
 | 
			
		||||
                return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
 | 
			
		||||
                        postFeedScrolledPositionSharedPreferences, postHistorySharedPreferences, postType,
 | 
			
		||||
                        sortType, postFilter, readPostList,name);
 | 
			
		||||
                        sortType, postFilter, readPostList,name, postEnricher);
 | 
			
		||||
            } else if (postType == PostPagingSource.TYPE_SEARCH) {
 | 
			
		||||
                return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
 | 
			
		||||
                        postFeedScrolledPositionSharedPreferences, postHistorySharedPreferences, name, query,
 | 
			
		||||
                        trendingSource, postType, sortType, postFilter, readPostList);
 | 
			
		||||
                        trendingSource, postType, sortType, postFilter, readPostList, postEnricher);
 | 
			
		||||
            } else if (postType == PostPagingSource.TYPE_SUBREDDIT || postType == PostPagingSource.TYPE_MULTI_REDDIT) {
 | 
			
		||||
                return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
 | 
			
		||||
                        postFeedScrolledPositionSharedPreferences, postHistorySharedPreferences, name,
 | 
			
		||||
                        postType, sortType, postFilter, readPostList);
 | 
			
		||||
                        postType, sortType, postFilter, readPostList, postEnricher);
 | 
			
		||||
            } else if (postType == PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE) {
 | 
			
		||||
                return (T) new PostViewModel(executor, retrofit, null, null, sharedPreferences,
 | 
			
		||||
                        null, null, name, postType, sortType,
 | 
			
		||||
                        postFilter, null);
 | 
			
		||||
                        postFilter, null, postEnricher);
 | 
			
		||||
            } else {
 | 
			
		||||
                return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
 | 
			
		||||
                        postFeedScrolledPositionSharedPreferences, postHistorySharedPreferences, name,
 | 
			
		||||
                        postType, sortType, postFilter, userWhere, readPostList);
 | 
			
		||||
                        postType, sortType, postFilter, userWhere, readPostList, postEnricher);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -15,6 +15,7 @@ import eu.toldi.infinityforlemmy.Flair;
 | 
			
		||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
 | 
			
		||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
 | 
			
		||||
import eu.toldi.infinityforlemmy.dto.SubmitPostDTO;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.UploadImageUtils;
 | 
			
		||||
import retrofit2.Call;
 | 
			
		||||
@@ -25,22 +26,24 @@ public class SubmitPost {
 | 
			
		||||
    public static void submitTextOrLinkPost(Executor executor, Handler handler, Retrofit oauthRetrofit, String accessToken,
 | 
			
		||||
                                            int communityId, String title, String body, String url,
 | 
			
		||||
                                            Flair flair, boolean isSpoiler, boolean isNSFW,
 | 
			
		||||
                                            boolean receivePostReplyNotifications, String kind,
 | 
			
		||||
                                            boolean receivePostReplyNotifications, String kind, PostEnricher postEnricher,
 | 
			
		||||
                                            SubmitPostListener submitPostListener) {
 | 
			
		||||
        submitPost(executor, handler, oauthRetrofit, accessToken, communityId, title, body,
 | 
			
		||||
                isNSFW, receivePostReplyNotifications, kind, url, submitPostListener);
 | 
			
		||||
                isNSFW, receivePostReplyNotifications, kind, url, postEnricher, submitPostListener);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void submitImagePost(Executor executor, Handler handler, RetrofitHolder mRetrofit,
 | 
			
		||||
                                       String accessToken, int communityId, String title, String body, Bitmap image,
 | 
			
		||||
                                       Flair flair, boolean isSpoiler, boolean isNSFW,
 | 
			
		||||
                                       boolean receivePostReplyNotifications, SubmitPostListener submitPostListener) {
 | 
			
		||||
                                       boolean receivePostReplyNotifications, PostEnricher postEnricher,
 | 
			
		||||
                                       SubmitPostListener submitPostListener) {
 | 
			
		||||
        try {
 | 
			
		||||
            String imageUrlOrError = UploadImageUtils.uploadImage(mRetrofit, accessToken, image);
 | 
			
		||||
            if (imageUrlOrError != null && !imageUrlOrError.startsWith("Error: ")) {
 | 
			
		||||
                submitPost(executor, handler, mRetrofit.getRetrofit(), accessToken,
 | 
			
		||||
                        communityId, title, body, isNSFW,
 | 
			
		||||
                        receivePostReplyNotifications, APIUtils.KIND_IMAGE, imageUrlOrError, submitPostListener);
 | 
			
		||||
                        receivePostReplyNotifications, APIUtils.KIND_IMAGE, imageUrlOrError,
 | 
			
		||||
                        postEnricher, submitPostListener);
 | 
			
		||||
            } else {
 | 
			
		||||
                submitPostListener.submitFailed(imageUrlOrError);
 | 
			
		||||
            }
 | 
			
		||||
@@ -53,17 +56,18 @@ public class SubmitPost {
 | 
			
		||||
    public static void submitCrosspost(Executor executor, Handler handler, Retrofit oauthRetrofit, String accessToken,
 | 
			
		||||
                                       int communityId, String title, String crosspostFullname,
 | 
			
		||||
                                       Flair flair, boolean isSpoiler, boolean isNSFW,
 | 
			
		||||
                                       boolean receivePostReplyNotifications, String kind,
 | 
			
		||||
                                       boolean receivePostReplyNotifications, String kind, PostEnricher postEnricher,
 | 
			
		||||
                                       SubmitPostListener submitPostListener) {
 | 
			
		||||
        submitPost(executor, handler, oauthRetrofit, accessToken, communityId, title, crosspostFullname,
 | 
			
		||||
                isNSFW, receivePostReplyNotifications, kind, null, submitPostListener);
 | 
			
		||||
                isNSFW, receivePostReplyNotifications, kind, null, postEnricher, submitPostListener);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static void submitPost(Executor executor, Handler handler, Retrofit oauthRetrofit, String accessToken,
 | 
			
		||||
                                   int communityId, String title, String content,
 | 
			
		||||
                                   boolean isNSFW,
 | 
			
		||||
                                   boolean receivePostReplyNotifications, String kind,
 | 
			
		||||
                                   @Nullable String posterUrl, SubmitPostListener submitPostListener) {
 | 
			
		||||
                                   @Nullable String posterUrl, PostEnricher postEnricher,
 | 
			
		||||
                                   SubmitPostListener submitPostListener) {
 | 
			
		||||
        LemmyAPI api = oauthRetrofit.create(LemmyAPI.class);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -73,7 +77,7 @@ public class SubmitPost {
 | 
			
		||||
            Response<String> response = submitPostCall.execute();
 | 
			
		||||
            if (response.isSuccessful()) {
 | 
			
		||||
                getSubmittedPost(executor, handler, response.body(), kind, oauthRetrofit, accessToken,
 | 
			
		||||
                        submitPostListener);
 | 
			
		||||
                        postEnricher, submitPostListener);
 | 
			
		||||
            } else {
 | 
			
		||||
                submitPostListener.submitFailed(response.message());
 | 
			
		||||
            }
 | 
			
		||||
@@ -84,10 +88,10 @@ public class SubmitPost {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static void getSubmittedPost(Executor executor, Handler handler, String response, String kind,
 | 
			
		||||
                                         Retrofit oauthRetrofit, String accessToken,
 | 
			
		||||
                                         Retrofit oauthRetrofit, String accessToken, PostEnricher postEnricher,
 | 
			
		||||
                                         SubmitPostListener submitPostListener) throws JSONException, IOException {
 | 
			
		||||
 | 
			
		||||
        ParsePost.parsePost(executor, handler, response, new ParsePost.ParsePostListener() {
 | 
			
		||||
        ParsePost.parsePost(executor, handler, postEnricher, response, new ParsePost.ParsePostListener() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onParsePostSuccess(Post post) {
 | 
			
		||||
                submitPostListener.submitSuccessful(post);
 | 
			
		||||
 
 | 
			
		||||
@@ -54,6 +54,7 @@ import eu.toldi.infinityforlemmy.events.SubmitPollPostEvent;
 | 
			
		||||
import eu.toldi.infinityforlemmy.events.SubmitTextOrLinkPostEvent;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.Post;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.SubmitPost;
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.enrich.PostEnricher;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.JSONUtils;
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.NotificationUtils;
 | 
			
		||||
@@ -102,6 +103,8 @@ public class SubmitPostService extends Service {
 | 
			
		||||
    CustomThemeWrapper mCustomThemeWrapper;
 | 
			
		||||
    @Inject
 | 
			
		||||
    Executor mExecutor;
 | 
			
		||||
    @Inject
 | 
			
		||||
    PostEnricher postEnricher;
 | 
			
		||||
    private Handler handler;
 | 
			
		||||
    private ServiceHandler serviceHandler;
 | 
			
		||||
 | 
			
		||||
@@ -221,7 +224,7 @@ public class SubmitPostService extends Service {
 | 
			
		||||
                                      String kind) {
 | 
			
		||||
        SubmitPost.submitTextOrLinkPost(mExecutor, handler, newAuthenticatorOauthRetrofit, selectedAccount.getAccessToken(),
 | 
			
		||||
                communityId, title, body, url, flair, isSpoiler,
 | 
			
		||||
                isNSFW, receivePostReplyNotifications, kind, new SubmitPost.SubmitPostListener() {
 | 
			
		||||
                isNSFW, receivePostReplyNotifications, kind, postEnricher, new SubmitPost.SubmitPostListener() {
 | 
			
		||||
                    @Override
 | 
			
		||||
                    public void submitSuccessful(Post post) {
 | 
			
		||||
                        handler.post(() -> EventBus.getDefault().post(new SubmitTextOrLinkPostEvent(true, post, null)));
 | 
			
		||||
@@ -243,7 +246,7 @@ public class SubmitPostService extends Service {
 | 
			
		||||
                                 String title, String content, Flair flair, boolean isSpoiler, boolean isNSFW,
 | 
			
		||||
                                 boolean receivePostReplyNotifications) {
 | 
			
		||||
        SubmitPost.submitCrosspost(executor, handler, newAuthenticatorOauthRetrofit, selectedAccount.getAccessToken(), communityId, title,
 | 
			
		||||
                content, flair, isSpoiler, isNSFW, receivePostReplyNotifications, APIUtils.KIND_CROSSPOST,
 | 
			
		||||
                content, flair, isSpoiler, isNSFW, receivePostReplyNotifications, APIUtils.KIND_CROSSPOST, postEnricher,
 | 
			
		||||
                new SubmitPost.SubmitPostListener() {
 | 
			
		||||
                    @Override
 | 
			
		||||
                    public void submitSuccessful(Post post) {
 | 
			
		||||
@@ -266,7 +269,8 @@ public class SubmitPostService extends Service {
 | 
			
		||||
        try {
 | 
			
		||||
            Bitmap resource = Glide.with(this).asBitmap().load(mediaUri).submit().get();
 | 
			
		||||
            SubmitPost.submitImagePost(mExecutor, handler, newAuthenticatorOauthRetrofit,
 | 
			
		||||
                    selectedAccount.getAccessToken(), communityId, title, body, resource, flair, isSpoiler, isNSFW, receivePostReplyNotifications,
 | 
			
		||||
                    selectedAccount.getAccessToken(), communityId, title, body, resource, flair, isSpoiler,
 | 
			
		||||
                    isNSFW, receivePostReplyNotifications, postEnricher,
 | 
			
		||||
                    new SubmitPost.SubmitPostListener() {
 | 
			
		||||
                        @Override
 | 
			
		||||
                        public void submitSuccessful(Post post) {
 | 
			
		||||
 
 | 
			
		||||
@@ -20,13 +20,16 @@ public class SiteInfo {
 | 
			
		||||
    private boolean enable_nsfw;
 | 
			
		||||
    private boolean community_creation_admin_only;
 | 
			
		||||
 | 
			
		||||
    private String version;
 | 
			
		||||
 | 
			
		||||
    private 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) {
 | 
			
		||||
    public SiteInfo(int id, String name, String version, String sidebar, String description, boolean enable_downvotes, boolean enable_nsfw, boolean community_creation_admin_only, List<BasicUserInfo> admins, SiteStatistics siteStatistics) {
 | 
			
		||||
        this.id = id;
 | 
			
		||||
        this.name = name;
 | 
			
		||||
        this.version = version;
 | 
			
		||||
        this.sidebar = sidebar;
 | 
			
		||||
        this.description = description;
 | 
			
		||||
        this.enable_downvotes = enable_downvotes;
 | 
			
		||||
@@ -72,6 +75,10 @@ public class SiteInfo {
 | 
			
		||||
        return siteStatistics;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getVersion() {
 | 
			
		||||
        return version;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static SiteInfo parseSiteInfo(String siteInfoJson) {
 | 
			
		||||
        try {
 | 
			
		||||
            JSONObject siteInfo = new JSONObject(siteInfoJson);
 | 
			
		||||
@@ -84,6 +91,7 @@ public class SiteInfo {
 | 
			
		||||
            String sidebar = null;
 | 
			
		||||
            if (site.has("sidebar"))
 | 
			
		||||
                sidebar = site.getString("sidebar");
 | 
			
		||||
            String version = siteInfo.getString("version");
 | 
			
		||||
 | 
			
		||||
            String description = null;
 | 
			
		||||
            if (site.has("description"))
 | 
			
		||||
@@ -106,7 +114,7 @@ public class SiteInfo {
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return new SiteInfo(id, name, sidebar, description, enable_downvotes, enable_nsfw, community_creation_admin_only, admins, SiteStatistics.parseSiteStatistics(counts));
 | 
			
		||||
            return new SiteInfo(id, name, version, sidebar, description, enable_downvotes, enable_nsfw, community_creation_admin_only, admins, SiteStatistics.parseSiteStatistics(counts));
 | 
			
		||||
        } catch (JSONException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
            return null;
 | 
			
		||||
 
 | 
			
		||||
@@ -48,7 +48,7 @@ public class ParseUserData {
 | 
			
		||||
        boolean isBot = personJson.getBoolean("bot_account");
 | 
			
		||||
        boolean isBanned = personJson.getBoolean("banned");
 | 
			
		||||
        boolean isLocal = personJson.getBoolean("local");
 | 
			
		||||
        boolean isAdmin = personJson.getBoolean("admin");
 | 
			
		||||
        boolean isAdmin = personJson.optBoolean("admin");
 | 
			
		||||
        boolean isDeleted = personJson.getBoolean("deleted");
 | 
			
		||||
 | 
			
		||||
        String description = "";
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,9 @@ import android.util.Base64;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
import okhttp3.Interceptor;
 | 
			
		||||
import okhttp3.MediaType;
 | 
			
		||||
import okhttp3.Request;
 | 
			
		||||
import okhttp3.RequestBody;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -142,12 +144,6 @@ public class APIUtils {
 | 
			
		||||
        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) {
 | 
			
		||||
        return RequestBody.create(s, MediaType.parse("text/plain"));
 | 
			
		||||
    }
 | 
			
		||||
@@ -159,4 +155,13 @@ public class APIUtils {
 | 
			
		||||
        params.put(APIUtils.USER_AGENT_KEY, APIUtils.USER_AGENT);
 | 
			
		||||
        return params;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Interceptor getOAuthInterceptor(String accessToken) {
 | 
			
		||||
        return chain -> {
 | 
			
		||||
            Request newRequest = chain.request().newBuilder()
 | 
			
		||||
                    .addHeader("Authorization", "Bearer " + accessToken)
 | 
			
		||||
                    .build();
 | 
			
		||||
            return chain.proceed(newRequest);
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -126,6 +126,7 @@ public class JSONUtils {
 | 
			
		||||
    public static final String Y_KEY = "y";
 | 
			
		||||
    public static final String DEST_KEY = "dest";
 | 
			
		||||
    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 RICHTEXT_KEY = "richtext";
 | 
			
		||||
    public static final String SUGGESTED_COMMENT_SORT_KEY = "suggested_comment_sort";
 | 
			
		||||
 
 | 
			
		||||
@@ -359,6 +359,8 @@ public class SharedPreferencesUtils {
 | 
			
		||||
    public static final String CURRENT_ACCOUNT_SHARED_PREFERENCES_FILE = "eu.toldi.infinityforlemmy.current_account";
 | 
			
		||||
    public static final String ACCOUNT_NAME = "account_name";
 | 
			
		||||
    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 REDGIFS_ACCESS_TOKEN = "redgifs_access_token";
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,11 @@
 | 
			
		||||
package eu.toldi.infinityforlemmy.post.enrich
 | 
			
		||||
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.Post
 | 
			
		||||
 | 
			
		||||
class CompositePostEnricher(private val enrichers: Set<PostEnricher>) : PostEnricher {
 | 
			
		||||
    override fun enrich(posts: Collection<Post>) {
 | 
			
		||||
        for (enricher in enrichers) {
 | 
			
		||||
            enricher.enrich(posts)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,7 @@
 | 
			
		||||
package eu.toldi.infinityforlemmy.post.enrich
 | 
			
		||||
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.Post
 | 
			
		||||
 | 
			
		||||
interface PostEnricher {
 | 
			
		||||
    fun enrich(posts: Collection<Post>)
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,56 @@
 | 
			
		||||
package eu.toldi.infinityforlemmy.post.enrich
 | 
			
		||||
 | 
			
		||||
import android.util.Log
 | 
			
		||||
import eu.toldi.infinityforlemmy.apis.RedgifsAPI
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.Post
 | 
			
		||||
import eu.toldi.infinityforlemmy.post.Post.Preview
 | 
			
		||||
import eu.toldi.infinityforlemmy.utils.JSONUtils
 | 
			
		||||
import org.json.JSONException
 | 
			
		||||
import org.json.JSONObject
 | 
			
		||||
import java.io.IOException
 | 
			
		||||
 | 
			
		||||
class RedGifsPostEnricher(private val redgifsAPI: RedgifsAPI) : PostEnricher {
 | 
			
		||||
    override fun enrich(posts: Collection<Post>) {
 | 
			
		||||
        val redGifsPosts = posts.filter { it.isRedgifs && it.previews.isEmpty() }
 | 
			
		||||
            .groupBy { it.gfycatId }
 | 
			
		||||
 | 
			
		||||
        if (redGifsPosts.isEmpty()) {
 | 
			
		||||
            return
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        try {
 | 
			
		||||
            val response = redgifsAPI.getRedgifsMultipleData(redGifsPosts.keys.joinToString(",")).execute()
 | 
			
		||||
            val body = response.body()
 | 
			
		||||
            if (response.isSuccessful && body != null) {
 | 
			
		||||
                try {
 | 
			
		||||
                    val gifsJson = JSONObject(body).getJSONArray(JSONUtils.GIFS_KEY)
 | 
			
		||||
                    for (i in 0 until gifsJson.length()) {
 | 
			
		||||
                        val gifJson = gifsJson.getJSONObject(i)
 | 
			
		||||
                        val id = gifJson.getString(JSONUtils.ID_KEY)
 | 
			
		||||
                        val width = gifJson.getInt(JSONUtils.WIDTH_KEY)
 | 
			
		||||
                        val height = gifJson.getInt(JSONUtils.HEIGHT_KEY)
 | 
			
		||||
                        val thumbnail = gifJson.getJSONObject(JSONUtils.URLS_KEY)
 | 
			
		||||
                            .getString(JSONUtils.THUMBNAIL_KEY)
 | 
			
		||||
 | 
			
		||||
                        val previews = ArrayList(listOf(Preview(thumbnail, width, height, null, null)))
 | 
			
		||||
 | 
			
		||||
                        redGifsPosts[id]?.forEach {
 | 
			
		||||
                            it.previews = previews
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                } catch (e: JSONException) {
 | 
			
		||||
                    Log.w(TAG, "Failed to parse JSON", e)
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                Log.w(TAG, "Failed fetch data. Status code ${response.code()}")
 | 
			
		||||
            }
 | 
			
		||||
        } catch (e: IOException) {
 | 
			
		||||
            Log.w(TAG, "Failed fetch data", e)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    companion object {
 | 
			
		||||
        private const val TAG = "RedGifsPostEnricher"
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -20,15 +20,28 @@
 | 
			
		||||
 | 
			
		||||
    <TextView
 | 
			
		||||
        android:id="@+id/subreddit_name_text_view_item_subreddit_listing"
 | 
			
		||||
        android:layout_width="0dp"
 | 
			
		||||
        android:layout_width="wrap_content"
 | 
			
		||||
        android:layout_height="wrap_content"
 | 
			
		||||
        android:layout_marginStart="32dp"
 | 
			
		||||
        android:fontFamily="?attr/font_family"
 | 
			
		||||
        android:maxLines="1"
 | 
			
		||||
        android:ellipsize="end"
 | 
			
		||||
        android:textSize="?attr/font_default"
 | 
			
		||||
        app:layout_constraintStart_toEndOf="@+id/subreddit_icon_gif_image_view_item_subreddit_listing"
 | 
			
		||||
        app:layout_constraintEnd_toStartOf="@id/barrier3"
 | 
			
		||||
        app:layout_constraintTop_toTopOf="parent" />
 | 
			
		||||
 | 
			
		||||
    <TextView
 | 
			
		||||
        android:id="@+id/community_instance_text_view_item_subreddit_listing"
 | 
			
		||||
        android:layout_width="wrap_content"
 | 
			
		||||
        android:layout_height="wrap_content"
 | 
			
		||||
        android:fontFamily="?attr/font_family"
 | 
			
		||||
        android:maxLines="1"
 | 
			
		||||
        android:ellipsize="end"
 | 
			
		||||
        android:textSize="?attr/font_default"
 | 
			
		||||
        app:layout_constraintStart_toEndOf="@+id/subreddit_name_text_view_item_subreddit_listing"
 | 
			
		||||
        app:layout_constraintTop_toTopOf="parent" />
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    <TextView
 | 
			
		||||
        android:id="@+id/subscriber_count_text_view_item_subreddit_listing"
 | 
			
		||||
        android:layout_width="0dp"
 | 
			
		||||
 
 | 
			
		||||
@@ -15,14 +15,33 @@
 | 
			
		||||
        android:layout_gravity="center_vertical"
 | 
			
		||||
        android:layout_marginEnd="32dp" />
 | 
			
		||||
 | 
			
		||||
    <TextView
 | 
			
		||||
        android:id="@+id/thing_name_text_view_item_subscribed_thing"
 | 
			
		||||
    <LinearLayout
 | 
			
		||||
        android:layout_width="0dp"
 | 
			
		||||
        android:layout_height="wrap_content"
 | 
			
		||||
        android:layout_height="match_parent"
 | 
			
		||||
        android:layout_weight="1"
 | 
			
		||||
        android:textSize="?attr/font_default"
 | 
			
		||||
        android:fontFamily="?attr/font_family"
 | 
			
		||||
        android:layout_gravity="center_vertical" />
 | 
			
		||||
        android:orientation="horizontal">
 | 
			
		||||
 | 
			
		||||
        <TextView
 | 
			
		||||
            android:id="@+id/thing_name_text_view_item_subscribed_thing"
 | 
			
		||||
            android:layout_width="wrap_content"
 | 
			
		||||
            android:layout_height="wrap_content"
 | 
			
		||||
            android:layout_gravity="center_vertical"
 | 
			
		||||
            android:ellipsize="end"
 | 
			
		||||
            android:fontFamily="?attr/font_family"
 | 
			
		||||
            android:gravity="start"
 | 
			
		||||
            android:maxLines="1"
 | 
			
		||||
            android:textSize="?attr/font_default" />
 | 
			
		||||
 | 
			
		||||
        <TextView
 | 
			
		||||
            android:id="@+id/thing_instance_text_view_item_subscribed_thing"
 | 
			
		||||
            android:layout_width="wrap_content"
 | 
			
		||||
            android:layout_height="wrap_content"
 | 
			
		||||
            android:layout_gravity="center_vertical"
 | 
			
		||||
            android:ellipsize="end"
 | 
			
		||||
            android:fontFamily="?attr/font_family"
 | 
			
		||||
            android:maxLines="1"
 | 
			
		||||
            android:textSize="?attr/font_default" />
 | 
			
		||||
    </LinearLayout>
 | 
			
		||||
 | 
			
		||||
    <ImageView
 | 
			
		||||
        android:id="@+id/favorite_image_view_item_subscribed_thing"
 | 
			
		||||
 
 | 
			
		||||
@@ -24,12 +24,27 @@
 | 
			
		||||
        android:layout_height="wrap_content"
 | 
			
		||||
        android:layout_gravity="center_vertical"
 | 
			
		||||
        android:layout_marginStart="32dp"
 | 
			
		||||
        android:maxLines="1"
 | 
			
		||||
        android:ellipsize="end"
 | 
			
		||||
        android:textSize="?attr/font_default"
 | 
			
		||||
        android:fontFamily="?attr/font_family"
 | 
			
		||||
        app:layout_constraintBottom_toBottomOf="parent"
 | 
			
		||||
        app:layout_constraintStart_toEndOf="@+id/user_icon_gif_image_view_item_user_listing"
 | 
			
		||||
        app:layout_constraintTop_toTopOf="parent" />
 | 
			
		||||
 | 
			
		||||
    <TextView
 | 
			
		||||
        android:id="@+id/user_instance_text_view_item_user_listing"
 | 
			
		||||
        android:layout_width="wrap_content"
 | 
			
		||||
        android:layout_height="wrap_content"
 | 
			
		||||
        android:layout_gravity="center_vertical"
 | 
			
		||||
        android:fontFamily="?attr/font_family"
 | 
			
		||||
        android:maxLines="1"
 | 
			
		||||
        android:ellipsize="end"
 | 
			
		||||
        android:textSize="?attr/font_default"
 | 
			
		||||
        app:layout_constraintBottom_toBottomOf="parent"
 | 
			
		||||
        app:layout_constraintStart_toEndOf="@+id/user_name_text_view_item_user_listing"
 | 
			
		||||
        app:layout_constraintTop_toTopOf="parent" />
 | 
			
		||||
 | 
			
		||||
    <ImageView
 | 
			
		||||
        android:id="@+id/subscribe_image_view_item_user_listing"
 | 
			
		||||
        android:layout_width="wrap_content"
 | 
			
		||||
 
 | 
			
		||||
@@ -543,17 +543,17 @@
 | 
			
		||||
    </string-array>
 | 
			
		||||
 | 
			
		||||
    <string-array name="settings_default_sort_time_values">
 | 
			
		||||
        <item>TopHour</item>
 | 
			
		||||
        <item>TopSixHour</item>
 | 
			
		||||
        <item>TopTwelveHour</item>
 | 
			
		||||
        <item>TopDay</item>
 | 
			
		||||
        <item>TopWeek</item>
 | 
			
		||||
        <item>TopMonth</item>
 | 
			
		||||
        <item>TopThreeMonths</item>
 | 
			
		||||
        <item>TopSixMonths</item>
 | 
			
		||||
        <item>TopNineMonths</item>
 | 
			
		||||
        <item>TopYear</item>
 | 
			
		||||
        <item>TopAll</item>
 | 
			
		||||
        <item>hour</item>
 | 
			
		||||
        <item>SixHour</item>
 | 
			
		||||
        <item>TwelveHour</item>
 | 
			
		||||
        <item>day</item>
 | 
			
		||||
        <item>week</item>
 | 
			
		||||
        <item>month</item>
 | 
			
		||||
        <item>ThreeMonths</item>
 | 
			
		||||
        <item>SixMonths</item>
 | 
			
		||||
        <item>NineMonths</item>
 | 
			
		||||
        <item>year</item>
 | 
			
		||||
        <item>all</item>
 | 
			
		||||
    </string-array>
 | 
			
		||||
 | 
			
		||||
    <string-array name="settings_default_search_result_tab">
 | 
			
		||||
 
 | 
			
		||||
@@ -24,8 +24,4 @@ allprojects {
 | 
			
		||||
        maven { url "https://jitpack.io" }
 | 
			
		||||
        jcenter()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
task clean(type: Delete) {
 | 
			
		||||
    delete rootProject.buildDir
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										32
									
								
								scripts/fixEventBus.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								scripts/fixEventBus.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,32 @@
 | 
			
		||||
import re
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def rearrange(filename):
 | 
			
		||||
    with open(filename, 'r') as file:
 | 
			
		||||
        content = file.read()
 | 
			
		||||
 | 
			
		||||
    # Regex to find the blocks of code to rearrange
 | 
			
		||||
    pattern = re.compile(r'(putIndex\(new SimpleSubscriberInfo\(.*?\)\);)', re.DOTALL)
 | 
			
		||||
    blocks = pattern.findall(content)
 | 
			
		||||
 | 
			
		||||
    # Sort blocks based on the class names mentioned in SimpleSubscriberInfo instances
 | 
			
		||||
    sorted_blocks = sorted(blocks, key=lambda x: re.search(r'SimpleSubscriberInfo\((.*?),', x).group(1))
 | 
			
		||||
 | 
			
		||||
    # Replace the original blocks with the sorted blocks
 | 
			
		||||
    sorted_content = pattern.sub(lambda match: sorted_blocks.pop(0), content)
 | 
			
		||||
 | 
			
		||||
    with open(filename, 'w') as file:
 | 
			
		||||
        file.write(sorted_content)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Project root relative to the script
 | 
			
		||||
project_root = __file__[:-len('/scripts/fixEventBus.py')]
 | 
			
		||||
 | 
			
		||||
path = './build/generated/ap_generated_sources/release/out/eu/toldi/infinityforlemmy/EventBusIndex.java'
 | 
			
		||||
 | 
			
		||||
# Print the path to the file to stderr
 | 
			
		||||
print(path, file=sys.stderr)
 | 
			
		||||
 | 
			
		||||
# Call the function with the path to EventBusIndex.java
 | 
			
		||||
rearrange(path)
 | 
			
		||||
		Reference in New Issue
	
	Block a user