Skip to content

Commit

Permalink
Migrate the API client from OpenVK Legacy to OpenVK Refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
tretdm committed Nov 25, 2023
1 parent 5ccd98d commit a7dc634
Show file tree
Hide file tree
Showing 107 changed files with 6,381 additions and 4,373 deletions.
2 changes: 1 addition & 1 deletion .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 38 additions & 71 deletions app/src/main/java/uk/openvk/android/refresh/Global.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.app.LocaleManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.graphics.Color;
Expand All @@ -13,15 +12,6 @@
import android.view.View;
import android.view.Window;

import androidx.annotation.ColorInt;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.content.res.ResourcesCompat;
import androidx.core.graphics.TypefaceCompat;
import androidx.core.os.LocaleListCompat;
import androidx.core.view.WindowInsetsControllerCompat;
import androidx.preference.PreferenceManager;

import com.google.android.material.color.MaterialColors;
import com.google.android.material.imageview.ShapeableImageView;
import com.google.android.material.shape.CornerFamily;
Expand All @@ -34,17 +24,20 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import uk.openvk.android.refresh.api.Account;
import uk.openvk.android.refresh.api.models.OvkLink;
import uk.openvk.android.refresh.api.models.WallPost;
import uk.openvk.android.refresh.ui.core.activities.AppActivity;
import uk.openvk.android.refresh.ui.core.activities.WallPostActivity;
import androidx.annotation.ColorInt;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.content.res.ResourcesCompat;
import androidx.core.graphics.TypefaceCompat;
import androidx.core.view.WindowInsetsControllerCompat;
import androidx.preference.PreferenceManager;
import uk.openvk.android.refresh.api.entities.OvkLink;

public class Global {
public static String bytesToHex(byte[] bytes) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < bytes.length; i++) {
String hex = Integer.toHexString(0xFF & bytes[i]);
for (byte aByte : bytes) {
String hex = Integer.toHexString(0xFF & aByte);
if (hex.length() == 1) {
sb.append('0');
}
Expand All @@ -68,37 +61,19 @@ public static String generateSHA256Hash(String text) {

public static void setColorTheme(Context ctx, String value, Window window) {
switch (value) {
case "blue":
ctx.setTheme(R.style.ApplicationTheme);
break;
case "red":
ctx.setTheme(R.style.ApplicationTheme_Color2);
break;
case "green":
ctx.setTheme(R.style.ApplicationTheme_Color3);
break;
case "violet":
ctx.setTheme(R.style.ApplicationTheme_Color4);
break;
case "orange":
ctx.setTheme(R.style.ApplicationTheme_Color5);
break;
case "teal":
ctx.setTheme(R.style.ApplicationTheme_Color6);
break;
case "ocean":
ctx.setTheme(R.style.ApplicationTheme_Color7);
break;
case "vk5x":
ctx.setTheme(R.style.ApplicationTheme_Color8);
break;
case "gray":
ctx.setTheme(R.style.ApplicationTheme_Color9);
break;
case "monet":
case "blue" -> ctx.setTheme(R.style.ApplicationTheme);
case "red" -> ctx.setTheme(R.style.ApplicationTheme_Color2);
case "green" -> ctx.setTheme(R.style.ApplicationTheme_Color3);
case "violet" -> ctx.setTheme(R.style.ApplicationTheme_Color4);
case "orange" -> ctx.setTheme(R.style.ApplicationTheme_Color5);
case "teal" -> ctx.setTheme(R.style.ApplicationTheme_Color6);
case "ocean" -> ctx.setTheme(R.style.ApplicationTheme_Color7);
case "vk5x" -> ctx.setTheme(R.style.ApplicationTheme_Color8);
case "gray" -> ctx.setTheme(R.style.ApplicationTheme_Color9);
case "monet" -> {
ctx.setTheme(R.style.ApplicationTheme_Monet);
MonetCompat.setup(ctx);
break;
}
}
WindowInsetsControllerCompat controllerCompat = new WindowInsetsControllerCompat(window, window.getDecorView());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Expand Down Expand Up @@ -156,26 +131,23 @@ public static void setAvatarShape(Context ctx, ShapeableImageView imageView) {
public static void setInterfaceFont(AppCompatActivity activity) {
SharedPreferences global_prefs = PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext());
String value = global_prefs.getString("interface_font", "system");
if(value.equals("inter")) {
activity.getTheme().applyStyle(R.style.ApplicationFont_Inter, true);
} else if(value.equals("open_sans")) {
activity.getTheme().applyStyle(R.style.ApplicationFont_OpenSans, true);
} else if(value.equals("raleway")) {
activity.getTheme().applyStyle(R.style.ApplicationFont_Raleway, true);
} else if(value.equals("roboto")) {
activity.getTheme().applyStyle(R.style.ApplicationFont_Roboto, true);
} else if(value.equals("rubik")) {
activity.getTheme().applyStyle(R.style.ApplicationFont_Rubik, true);
switch (value) {
case "inter" ->
activity.getTheme().applyStyle(R.style.ApplicationFont_Inter, true);
case "open_sans" ->
activity.getTheme().applyStyle(R.style.ApplicationFont_OpenSans, true);
case "raleway" ->
activity.getTheme().applyStyle(R.style.ApplicationFont_Raleway, true);
case "roboto" ->
activity.getTheme().applyStyle(R.style.ApplicationFont_Roboto, true);
case "rubik" ->
activity.getTheme().applyStyle(R.style.ApplicationFont_Rubik, true);
}
}

public static boolean checkMonet(Context ctx) {
String value = PreferenceManager.getDefaultSharedPreferences(ctx).getString("theme_color", "blue");
if(value.equals("monet")) {
return true;
} else {
return false;
}
return value.equals("monet");
}

@ColorInt
Expand Down Expand Up @@ -255,8 +227,9 @@ public static Typeface getFlexibleTypeface(Context ctx, int weight) {
public static Spanned formatLinksAsHtml(String original_text) {
String[] lines = original_text.split("\r\n|\r|\n");
StringBuilder text_llines = new StringBuilder();
Pattern pattern = Pattern.compile("\\[(.+?)\\]|" +
"((http|https)://)(www.)?[a-zA-Z0-9@:%._\\+~#?&//=]{1,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%._\\+~#?&//=]*)");
Pattern pattern = Pattern.compile("\\[(.+?)]|" +
"((http|https)://)(www.)?[a-zA-Z0-9@:%._+~#?&/=]{1,256}\\.[a-z]{2,6}\\b" +
"([-a-zA-Z0-9@:%._+~#?&/=]*)");
Matcher matcher = pattern.matcher(original_text);
boolean regexp_search = matcher.find();
String text = original_text.replaceAll("&lt;", "<").replaceAll("&gt;", ">")
Expand All @@ -267,7 +240,8 @@ public static Spanned formatLinksAsHtml(String original_text) {
String block = matcher.group();
if(block.startsWith("[") && block.endsWith("]")) {
OvkLink link = new OvkLink();
String[] markup = block.replace("[", "").replace("]", "").split("\\|");
String[] markup = block.replace("[", "")
.replace("]", "").split("\\|");
link.screen_name = markup[0];
if (markup.length == 2) {
if (markup[0].startsWith("id")) {
Expand Down Expand Up @@ -295,13 +269,6 @@ public static Spanned formatLinksAsHtml(String original_text) {
}
}

public static void openPostComments(Account account, WallPost post, Context ctx) {
Intent intent = new Intent(ctx, WallPostActivity.class);
intent.putExtra("post", post);
intent.putExtra("counters", post.counters);
ctx.startActivity(intent);
}

public static int getMonetIntColor(MonetCompat monet, String type, int brightness) {
if(type.equals("neutral1")) {
return Objects.requireNonNull(monet.getMonetColors()
Expand Down
34 changes: 29 additions & 5 deletions app/src/main/java/uk/openvk/android/refresh/OvkApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@
import android.os.LocaleList;
import android.preference.PreferenceManager;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.os.LocaleListCompat;

import com.kieronquinn.monetcompat.core.MonetCompat;

import java.util.Locale;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.os.LocaleListCompat;
import uk.openvk.android.refresh.api.wrappers.OvkAPIWrapper;
import uk.openvk.android.refresh.longpoll_api.LongPollService;
import uk.openvk.android.refresh.services.LongPollService;

public class OvkApplication extends Application {
public static final String API_TAG = "OVK-API";
public static final String LP_TAG = "OVK-LP";
public static final String DL_TAG = "OVK-DLM";
public static final String UL_TAG = "OVK-ULM";
public static final String APP_TAG = "OpenVK";
public static boolean isTablet;
public String version;
public LongPollService longPollService;
Expand Down Expand Up @@ -143,4 +147,24 @@ public static LocaleListCompat getLocaleList(Context ctx) {
}
}

public SharedPreferences getAccountPreferences() {
SharedPreferences prefs = getSharedPreferences(
String.format("instance_a%s_%s", getCurrentUserId(), getCurrentInstance()), 0);
if(prefs != null && prefs.contains("server") &&
prefs.getString("server", "").equals(getCurrentInstance())) {
return prefs;
} else {
return getSharedPreferences("instance", 0);
}
}

private long getCurrentUserId() {
return PreferenceManager.getDefaultSharedPreferences(this)
.getLong("current_uid", 0);
}
public String getCurrentInstance() {
return PreferenceManager.getDefaultSharedPreferences(this)
.getString("current_instance", "");
}

}
32 changes: 0 additions & 32 deletions app/src/main/java/uk/openvk/android/refresh/api/Authorization.java

This file was deleted.

Loading

0 comments on commit a7dc634

Please sign in to comment.