Rework module validation and setup
Signed-off-by: androidacy-user <opensource@androidacy.com>pull/27/head
parent
e17e839f2d
commit
fc3406ce08
@ -0,0 +1,56 @@
|
|||||||
|
package com.fox2code.mmm.utils;
|
||||||
|
|
||||||
|
// Original written by tsuharesu
|
||||||
|
// Adapted to create a "drop it in and watch it work" approach by Nikhil Jha.
|
||||||
|
// Just add your package statement and drop it in the folder with all your other classes.
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import com.fox2code.mmm.MainApplication;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
import okhttp3.Interceptor;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This interceptor put all the Cookies in Preferences in the Request.
|
||||||
|
* Your implementation on how to get the Preferences may ary, but this will work 99% of the time.
|
||||||
|
*/
|
||||||
|
public class AddCookiesInterceptor implements Interceptor {
|
||||||
|
public static final String PREF_COOKIES = "PREF_COOKIES";
|
||||||
|
// We're storing our stuff in a database made just for cookies called PREF_COOKIES.
|
||||||
|
// I reccomend you do this, and don't change this default value.
|
||||||
|
private final Context context;
|
||||||
|
|
||||||
|
public AddCookiesInterceptor(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Response intercept(Interceptor.Chain chain) throws IOException {
|
||||||
|
Request.Builder builder = chain.request().newBuilder();
|
||||||
|
|
||||||
|
HashSet<String> preferences = (HashSet<String>) MainApplication.getSharedPreferences().getStringSet(PREF_COOKIES, new HashSet<>());
|
||||||
|
|
||||||
|
// Use the following if you need everything in one line.
|
||||||
|
// Some APIs die if you do it differently.
|
||||||
|
StringBuilder cookiestring = new StringBuilder();
|
||||||
|
for (String cookie : preferences) {
|
||||||
|
String[] parser = cookie.split(";");
|
||||||
|
cookiestring.append(parser[0]).append("; ");
|
||||||
|
}
|
||||||
|
builder.addHeader("Cookie", cookiestring.toString());
|
||||||
|
|
||||||
|
for (String cookie : preferences) {
|
||||||
|
builder.addHeader("Cookie", cookie);
|
||||||
|
}
|
||||||
|
|
||||||
|
return chain.proceed(builder.build());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
package com.fox2code.mmm.utils;
|
||||||
|
|
||||||
|
// Original written by tsuharesu
|
||||||
|
// Adapted to create a "drop it in and watch it work" approach by Nikhil Jha.
|
||||||
|
// Just add your package statement and drop it in the folder with all your other classes.
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import com.fox2code.mmm.MainApplication;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
import okhttp3.Interceptor;
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
|
public class ReceivedCookiesInterceptor implements Interceptor {
|
||||||
|
private final Context context;
|
||||||
|
public ReceivedCookiesInterceptor(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
} // AddCookiesInterceptor()
|
||||||
|
@NonNull
|
||||||
|
@SuppressLint({"MutatingSharedPrefs", "ApplySharedPref"})
|
||||||
|
@Override
|
||||||
|
public Response intercept(Chain chain) throws IOException {
|
||||||
|
Response originalResponse = chain.proceed(chain.request());
|
||||||
|
|
||||||
|
if (!originalResponse.headers("Set-Cookie").isEmpty()) {
|
||||||
|
HashSet<String> cookies = (HashSet<String>) MainApplication.getSharedPreferences().getStringSet("PREF_COOKIES", new HashSet<>());
|
||||||
|
|
||||||
|
cookies.addAll(originalResponse.headers("Set-Cookie"));
|
||||||
|
|
||||||
|
SharedPreferences.Editor memes = MainApplication.getSharedPreferences().edit();
|
||||||
|
memes.putStringSet("PREF_COOKIES", cookies).apply();
|
||||||
|
memes.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
return originalResponse;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,38 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
|
|
||||||
<!-- Options for system, dark, light, black, transparent_light -->
|
|
||||||
<!-- Only one of these can be selected at a time -->
|
|
||||||
<!-- Radio buttons -->
|
|
||||||
<!-- Themes are taken from theme_values_names string array -->
|
|
||||||
<item
|
|
||||||
android:id="@+id/theme"
|
|
||||||
android:icon="@drawable/ic_baseline_design_services_24"
|
|
||||||
android:title="@string/theme"
|
|
||||||
app:showAsAction="never">
|
|
||||||
<menu>
|
|
||||||
<group android:checkableBehavior="single">
|
|
||||||
<!-- System is default selected -->
|
|
||||||
<item
|
|
||||||
android:id="@+id/theme_system"
|
|
||||||
android:title="@string/theme_system"
|
|
||||||
app:showAsAction="never" />
|
|
||||||
<item
|
|
||||||
android:id="@+id/theme_dark"
|
|
||||||
android:title="@string/theme_dark"
|
|
||||||
app:showAsAction="never" />
|
|
||||||
<item
|
|
||||||
android:id="@+id/theme_black"
|
|
||||||
android:title="@string/theme_black"
|
|
||||||
app:showAsAction="never" />
|
|
||||||
<item
|
|
||||||
android:id="@+id/theme_transparent_light"
|
|
||||||
android:title="@string/theme_transparent_light"
|
|
||||||
app:showAsAction="never" />
|
|
||||||
<item
|
|
||||||
android:id="@+id/theme_light"
|
|
||||||
android:title="@string/theme_light"
|
|
||||||
app:showAsAction="never" />
|
|
||||||
</group>
|
|
||||||
</menu>
|
|
||||||
</item>
|
|
||||||
</menu>
|
|
||||||
Loading…
Reference in New Issue