Skip to content

Commit

Permalink
build 15
Browse files Browse the repository at this point in the history
  • Loading branch information
tretdm committed Feb 11, 2023
1 parent 210f1c1 commit a7ba31c
Show file tree
Hide file tree
Showing 25 changed files with 650 additions and 59 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "uk.openvk.android.refresh"
minSdk 21
targetSdk 33
versionCode 14
versionName "0.0.14.alpha"
versionCode 15
versionName "0.0.15.alpha"
}

buildTypes {
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
android:windowSoftInputMode="adjustResize"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|mcc|mnc|uiMode"
android:label="@string/title_activity_auth" />

<activity
android:name=".ui.core.activities.MainSettingsActivity"
android:exported="false"
android:windowSoftInputMode="adjustResize"
android:label="@string/nav_settings"
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|mcc|mnc|uiMode"
android:theme="@style/ApplicationTheme.NoActionBar"
tools:ignore="RedundantLabel" />
<activity
android:name=".ui.core.activities.AppActivity"
android:exported="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ private void setMonetTheme() {
BottomNavigationView b_navView = findViewById(R.id.bottom_nav_view);
if (isDarkTheme) {
colors = new int[]{
Objects.requireNonNull(getMonet().getMonetColors().getAccent1().get(100)).toLinearSrgb().toSrgb().quantize8(),
Objects.requireNonNull(getMonet().getMonetColors().getAccent1().get(200)).toLinearSrgb().toSrgb().quantize8(),
Global.adjustAlpha(colorOnSurface, 0.6f)
};
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,26 @@
import android.os.Looper;
import android.os.Message;
import android.preference.PreferenceManager;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.WindowCompat;
import androidx.core.view.WindowInsetsControllerCompat;
import androidx.fragment.app.FragmentTransaction;

import com.google.android.material.color.MaterialColors;
import com.google.android.material.snackbar.Snackbar;
import com.kieronquinn.monetcompat.app.MonetCompatActivity;
import com.kieronquinn.monetcompat.core.MonetCompat;

import java.util.Locale;
import java.util.Objects;

import dev.kdrag0n.monet.theme.ColorScheme;
import uk.openvk.android.refresh.Global;
Expand Down Expand Up @@ -98,6 +102,20 @@ public void onKeyboardStateChanged(boolean state) {
e.printStackTrace();
}
}
setAppBar();
}

private void setAppBar() {
((Toolbar) findViewById(R.id.toolbar)).setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if(item.getItemId() == R.id.settings) {
Intent intent = new Intent(getApplicationContext(), MainSettingsActivity.class);
startActivity(intent);
}
return false;
}
});
}

@Override
Expand Down Expand Up @@ -172,8 +190,23 @@ private void receiveState(int message, Bundle data) {
TextView snackTextView = (TextView) snackbarView.findViewById(com.google.android.material.R.id.snackbar_text);
snackTextView.setMaxLines(3);
snackTextView.setTextColor(getResources().getColor(R.color.primaryTextColor));
snackbar.setBackgroundTint(Color.WHITE);
snackbar.setActionTextColor(getResources().getColor(R.color.accentColor));
if(global_prefs.getBoolean("dark_theme", false)) {
snackbar.setBackgroundTint(getResources().getColor(R.color.navbarColor));
} else {
snackbar.setBackgroundTint(Color.WHITE);
}
if(Global.checkMonet(this)) {
if(global_prefs.getBoolean("dark_theme", false)) {
snackbar.setActionTextColor(Objects.requireNonNull(
getMonet().getMonetColors().getAccent1().get(100)).toLinearSrgb().toSrgb().quantize8());
} else {
snackbar.setActionTextColor(Objects.requireNonNull(
getMonet().getMonetColors().getAccent1().get(500)).toLinearSrgb().toSrgb().quantize8());
}
} else {
snackbar.setActionTextColor(MaterialColors.getColor(this, androidx.appcompat.R.attr.colorAccent,
getResources().getColor(R.color.accentColor)));
}
Button snackActionBtn = (Button) snackbarView.findViewById(com.google.android.material.R.id.snackbar_action);
snackActionBtn.setLetterSpacing(0);
snackbar.show();
Expand All @@ -192,8 +225,23 @@ public void onClick(View view) {
TextView snackTextView = (TextView) snackbarView.findViewById(com.google.android.material.R.id.snackbar_text);
snackTextView.setMaxLines(3);
snackTextView.setTextColor(getResources().getColor(R.color.primaryTextColor));
snackbar.setBackgroundTint(Color.WHITE);
snackbar.setActionTextColor(getResources().getColor(R.color.accentColor));
if(global_prefs.getBoolean("dark_theme", false)) {
snackbar.setBackgroundTint(getResources().getColor(R.color.navbarColor));
} else {
snackbar.setBackgroundTint(Color.WHITE);
}
if(Global.checkMonet(this)) {
if(global_prefs.getBoolean("dark_theme", false)) {
snackbar.setActionTextColor(Objects.requireNonNull(
getMonet().getMonetColors().getAccent1().get(100)).toLinearSrgb().toSrgb().quantize8());
} else {
snackbar.setActionTextColor(Objects.requireNonNull(
getMonet().getMonetColors().getAccent1().get(500)).toLinearSrgb().toSrgb().quantize8());
}
} else {
snackbar.setActionTextColor(MaterialColors.getColor(this, androidx.appcompat.R.attr.colorAccent,
getResources().getColor(R.color.accentColor)));
}
Button snackActionBtn = (Button) snackbarView.findViewById(com.google.android.material.R.id.snackbar_action);
snackActionBtn.setLetterSpacing(0);
snackbar.show();
Expand All @@ -205,10 +253,25 @@ public void onClick(View view) {
snackbar = Snackbar.make(auth_layout, R.string.auth_instance_unavailable, Snackbar.LENGTH_LONG);
View snackbarView = snackbar.getView();
TextView snackTextView = (TextView) snackbarView.findViewById(com.google.android.material.R.id.snackbar_text);
snackbar.setBackgroundTint(Color.WHITE);
if(global_prefs.getBoolean("dark_theme", false)) {
snackbar.setBackgroundTint(getResources().getColor(R.color.navbarColor));
} else {
snackbar.setBackgroundTint(Color.WHITE);
}
snackTextView.setMaxLines(3);
snackTextView.setTextColor(getResources().getColor(R.color.primaryTextColor));
snackbar.setActionTextColor(getResources().getColor(R.color.accentColor));
if(Global.checkMonet(this)) {
if(global_prefs.getBoolean("dark_theme", false)) {
snackbar.setActionTextColor(Objects.requireNonNull(
getMonet().getMonetColors().getAccent1().get(100)).toLinearSrgb().toSrgb().quantize8());
} else {
snackbar.setActionTextColor(Objects.requireNonNull(
getMonet().getMonetColors().getAccent1().get(500)).toLinearSrgb().toSrgb().quantize8());
}
} else {
snackbar.setActionTextColor(MaterialColors.getColor(this, androidx.appcompat.R.attr.colorAccent,
getResources().getColor(R.color.accentColor)));
}
Button snackActionBtn = (Button) snackbarView.findViewById(com.google.android.material.R.id.snackbar_action);
snackActionBtn.setLetterSpacing(0);
snackbar.show();
Expand All @@ -221,9 +284,24 @@ public void onClick(View view) {
View snackbarView = snackbar.getView();
TextView snackTextView = (TextView) snackbarView.findViewById(com.google.android.material.R.id.snackbar_text);
snackTextView.setMaxLines(3);
snackbar.setBackgroundTint(Color.WHITE);
if(global_prefs.getBoolean("dark_theme", false)) {
snackbar.setBackgroundTint(getResources().getColor(R.color.navbarColor));
} else {
snackbar.setBackgroundTint(Color.WHITE);
}
snackTextView.setTextColor(getResources().getColor(R.color.primaryTextColor));
snackbar.setActionTextColor(getResources().getColor(R.color.accentColor));
if(Global.checkMonet(this)) {
if(global_prefs.getBoolean("dark_theme", false)) {
snackbar.setActionTextColor(Objects.requireNonNull(
getMonet().getMonetColors().getAccent1().get(100)).toLinearSrgb().toSrgb().quantize8());
} else {
snackbar.setActionTextColor(Objects.requireNonNull(
getMonet().getMonetColors().getAccent1().get(500)).toLinearSrgb().toSrgb().quantize8());
}
} else {
snackbar.setActionTextColor(MaterialColors.getColor(this, androidx.appcompat.R.attr.colorAccent,
getResources().getColor(R.color.accentColor)));
}
Button snackActionBtn = (Button) snackbarView.findViewById(com.google.android.material.R.id.snackbar_action);
snackActionBtn.setLetterSpacing(0);
snackbar.show();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
package uk.openvk.android.refresh.ui.core.activities;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.preference.PreferenceManager;

import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.navigation.NavigationView;
import com.kieronquinn.monetcompat.app.MonetCompatActivity;
import com.kieronquinn.monetcompat.core.MonetCompat;

import java.util.Locale;
import java.util.Objects;

import dev.kdrag0n.monet.theme.ColorScheme;
import uk.openvk.android.refresh.Global;
import uk.openvk.android.refresh.OvkApplication;
import uk.openvk.android.refresh.R;
import uk.openvk.android.refresh.api.Account;
import uk.openvk.android.refresh.api.Likes;
import uk.openvk.android.refresh.api.Users;
import uk.openvk.android.refresh.api.Wall;
import uk.openvk.android.refresh.api.enumerations.HandlerMessages;
import uk.openvk.android.refresh.api.models.User;
import uk.openvk.android.refresh.api.models.WallPost;
import uk.openvk.android.refresh.api.wrappers.DownloadManager;
import uk.openvk.android.refresh.api.wrappers.OvkAPIWrapper;
import uk.openvk.android.refresh.ui.core.fragments.app.AboutApplicationFragment;
import uk.openvk.android.refresh.ui.core.fragments.app.MainSettingsFragment;
import uk.openvk.android.refresh.ui.core.fragments.app.PersonalizationFragment;
import uk.openvk.android.refresh.ui.core.fragments.app.ProfileFragment;
import uk.openvk.android.refresh.ui.wrappers.LocaleContextWrapper;

public class MainSettingsActivity extends MonetCompatActivity {
private SharedPreferences global_prefs;
private SharedPreferences instance_prefs;
public Handler handler;
private OvkAPIWrapper ovk_api;
private DownloadManager downloadManager;
private Wall wall;
private Account account;
private Likes likes;
private FragmentTransaction ft;
private String args;
private MaterialToolbar toolbar;
private Users users;
private User user;
private boolean isDarkTheme;
private MainSettingsFragment mainSettingsFragment;
private PersonalizationFragment personalizationFragment;
private AboutApplicationFragment aboutAppFragment;
private Fragment selectedFragment;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
global_prefs = PreferenceManager.getDefaultSharedPreferences(this);
isDarkTheme = global_prefs.getBoolean("dark_theme", false);
Global.setColorTheme(this, global_prefs.getString("theme_color", "blue"));
Global.setInterfaceFont(this);
instance_prefs = getSharedPreferences("instance", 0);
setContentView(R.layout.intent_view);
setMonetTheme();
setAppBar();
createFragments();
}

@Override
protected void attachBaseContext(Context newBase) {
Locale languageType = OvkApplication.getLocale(newBase);
super.attachBaseContext(LocaleContextWrapper.wrap(newBase, languageType));
}

private void setMonetTheme() {
if(Global.checkMonet(this)) {
MaterialToolbar toolbar = findViewById(R.id.app_toolbar);
if (!isDarkTheme) {
toolbar.setBackgroundColor(Objects.requireNonNull(getMonet().getMonetColors().getAccent1().get(600)).toLinearSrgb().toSrgb().quantize8());
getWindow().setStatusBarColor(Objects.requireNonNull(getMonet().getMonetColors().getAccent1().get(700)).toLinearSrgb().toSrgb().quantize8());
}
}
}

private void createFragments() {
mainSettingsFragment = new MainSettingsFragment();
personalizationFragment = new PersonalizationFragment();
aboutAppFragment = new AboutApplicationFragment();
setAppBar();
FragmentManager fm = getSupportFragmentManager();
ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.fragment_screen, mainSettingsFragment, "settings");
ft.add(R.id.fragment_screen, personalizationFragment, "personalization");
ft.add(R.id.fragment_screen, aboutAppFragment, "about_app");
ft.commit();
ft = getSupportFragmentManager().beginTransaction();
ft.hide(personalizationFragment);
ft.hide(aboutAppFragment);
ft.commit();
ft = getSupportFragmentManager().beginTransaction();
selectedFragment = getSupportFragmentManager().findFragmentByTag("settings");
}

private void setAppBar() {
toolbar = findViewById(R.id.app_toolbar);
toolbar.setNavigationIcon(R.drawable.ic_arrow_back);
toolbar.setTitle(getResources().getString(R.string.nav_settings));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onBackPressed();
}
});
if(!Global.checkMonet(this)) {
TypedValue typedValue = new TypedValue();
boolean isDarkThemeEnabled = (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
if (isDarkThemeEnabled) {
getTheme().resolveAttribute(androidx.appcompat.R.attr.background, typedValue, true);
} else {
getTheme().resolveAttribute(androidx.appcompat.R.attr.colorPrimaryDark, typedValue, true);
}
getWindow().setStatusBarColor(typedValue.data);
}
}

@Override
public void onMonetColorsChanged(@NonNull MonetCompat monet, @NonNull ColorScheme monetColors, boolean isInitialChange) {
super.onMonetColorsChanged(monet, monetColors, isInitialChange);
getMonet().updateMonetColors();
setMonetTheme();
}

public void switchFragment(String tag) {
FragmentManager fm = getSupportFragmentManager();
ft = getSupportFragmentManager().beginTransaction();
ft.hide(Objects.requireNonNull(fm.findFragmentByTag("settings")));
ft.hide(Objects.requireNonNull(fm.findFragmentByTag("personalization")));
ft.hide(Objects.requireNonNull(fm.findFragmentByTag("about_app")));
if(selectedFragment == null) selectedFragment = getSupportFragmentManager().findFragmentByTag("settings");
switch (tag) {
case "settings":
ft.hide(selectedFragment);
selectedFragment = Objects.requireNonNull(fm.findFragmentByTag("settings"));
ft.show(selectedFragment);
((MaterialToolbar) findViewById(R.id.app_toolbar)).setTitle(R.string.nav_settings);
((MaterialToolbar) findViewById(R.id.app_toolbar)).setNavigationIcon(R.drawable.ic_arrow_back);
break;
case "personalization":
ft.hide(selectedFragment);
selectedFragment = Objects.requireNonNull(fm.findFragmentByTag("personalization"));
ft.show(selectedFragment);
((MaterialToolbar) findViewById(R.id.app_toolbar)).setTitle(R.string.pref_personalization);
((MaterialToolbar) findViewById(R.id.app_toolbar)).setNavigationIcon(R.drawable.ic_arrow_back);
break;
case "about_app":
ft.hide(selectedFragment);
selectedFragment = Objects.requireNonNull(fm.findFragmentByTag("about_app"));
ft.show(selectedFragment);
((MaterialToolbar) findViewById(R.id.app_toolbar)).setTitle(R.string.pref_about_app);
((MaterialToolbar) findViewById(R.id.app_toolbar)).setNavigationIcon(R.drawable.ic_arrow_back);
break;
}
ft.commit();
}

@Override
public void onBackPressed() {
if(selectedFragment != null && selectedFragment != mainSettingsFragment) {
switchFragment("settings");
} else {
super.onBackPressed();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
MonetCompat monet = MonetCompat.getInstance();
boolean isDarkTheme = PreferenceManager.getDefaultSharedPreferences(requireContext()).getBoolean("dark_theme", false);
if(isDarkTheme) {
((Button) view.findViewById(R.id.source_code_btn)).setTextColor(ColorStateList.valueOf(Objects.requireNonNull(monet.getMonetColors().getAccent1().get(100)).toLinearSrgb().toSrgb().quantize8()));
((Button) view.findViewById(R.id.source_code_btn)).setTextColor(ColorStateList.valueOf(Objects.requireNonNull(monet.getMonetColors().getAccent1().get(200)).toLinearSrgb().toSrgb().quantize8()));
} else {
((Button) view.findViewById(R.id.source_code_btn)).setTextColor(ColorStateList.valueOf(Objects.requireNonNull(monet.getMonetColors().getAccent1().get(500)).toLinearSrgb().toSrgb().quantize8()));
}
Expand Down
Loading

0 comments on commit a7ba31c

Please sign in to comment.