Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AuthorActivity and PermissionActivity as well as associated code #252

Merged
merged 6 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ dependencies {
implementation 'com.google.android.material:material:1.11.0'
implementation 'com.jakewharton:process-phoenix:3.0.0'
implementation 'com.squareup.retrofit2:converter-gson:2.11.0'
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation 'io.sentry:sentry-android:7.7.0'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.13'
}
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
<activity
android:name=".StatusActivity"
android:exported="false" />
<activity android:name=".AuthorActivity"
android:exported="false" />
<activity android:name=".PermissionActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package com.doubleangels.nextdnsmanagement;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ImageView;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.Toolbar;
import androidx.lifecycle.LifecycleOwner;

import com.doubleangels.nextdnsmanagement.protocoltest.VisualIndicator;
import com.doubleangels.nextdnsmanagement.sentry.SentryInitializer;
import com.doubleangels.nextdnsmanagement.sentry.SentryManager;

import java.util.Locale;

public class AuthorActivity extends AppCompatActivity {

public SentryManager sentryManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_author);
sentryManager = new SentryManager(this);
SharedPreferences sharedPreferences = this.getSharedPreferences("preferences", Context.MODE_PRIVATE);
try {
if (sentryManager.isSentryEnabled()) {
SentryInitializer.initialize(this);
}
setupToolbar();
setupLanguage();
setupDarkMode(sharedPreferences);
setupVisualIndicator(sentryManager, this);
setupPersonalLinks(sentryManager);
} catch (Exception e) {
sentryManager.captureException(e);
}
}

private void setupToolbar() {
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(false);
}
ImageView imageView = findViewById(R.id.connectionStatus);
imageView.setOnClickListener(v -> startActivity(new Intent(this, StatusActivity.class)));
}

/** @noinspection deprecation*/
private void setupLanguage() {
Resources resources = getResources();
Configuration configuration = resources.getConfiguration();
Locale appLocale = configuration.getLocales().get(0);
if (appLocale != null) {
Locale.setDefault(appLocale);
configuration.setLocale(appLocale);
resources.updateConfiguration(configuration, resources.getDisplayMetrics());
}
}

private void setupDarkMode(SharedPreferences sharedPreferences) {
String darkModeOverride = sharedPreferences.getString("darkmode_override", "match");
if (darkModeOverride.contains("match")) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
} else if (darkModeOverride.contains("on")) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
}

private void setupVisualIndicator(SentryManager sentryManager, LifecycleOwner lifecycleOwner) {
try {
new VisualIndicator(this).initiateVisualIndicator(this, lifecycleOwner, this);
} catch (Exception e) {
sentryManager.captureException(e);
}
}

public void setupPersonalLinks(SentryManager sentryManager) {
try {
ImageView githubButton = findViewById(R.id.githubImageView);
ImageView emailButton = findViewById(R.id.emailImageView);
ImageView websiteButton = findViewById(R.id.websiteImageView);
githubButton.setOnClickListener(view -> {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.github_profile_url)));
startActivity(intent);
});

emailButton.setOnClickListener(view -> {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse("mailto:nextdns@doubleangels.com"));
startActivity(Intent.createChooser(emailIntent, "Send Email"));
});

websiteButton.setOnClickListener(view -> {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.author_url)));
startActivity(intent);
});
} catch (Exception e) {
sentryManager.captureException(e);
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_back_only, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.back) {
Intent mainIntent = new Intent(this, SettingsActivity.class);
startActivity(mainIntent);
}
return super.onContextItemSelected(item);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ protected void onCreate(Bundle savedInstanceState) {
}
if (sentryManager.isSentryEnabled()) {
sentryManager.captureMessage("Sentry is enabled for NextDNS Manager.");
SentryInitializer sentryInitializer = new SentryInitializer();
sentryInitializer.execute(this);
SentryInitializer.initialize(this);
}
setupToolbar();
String appLocale = setupLanguage();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package com.doubleangels.nextdnsmanagement;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PermissionInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ImageView;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.Toolbar;
import androidx.lifecycle.LifecycleOwner;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.doubleangels.nextdnsmanagement.adaptors.PermissionsAdapter;
import com.doubleangels.nextdnsmanagement.protocoltest.VisualIndicator;
import com.doubleangels.nextdnsmanagement.sentry.SentryInitializer;
import com.doubleangels.nextdnsmanagement.sentry.SentryManager;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

public class PermissionActivity extends AppCompatActivity {

public SentryManager sentryManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_permission);
sentryManager = new SentryManager(this);
SharedPreferences sharedPreferences = this.getSharedPreferences("preferences", Context.MODE_PRIVATE);
try {
if (sentryManager.isSentryEnabled()) {
SentryInitializer.initialize(this);
}
setupToolbar();
setupLanguage();
setupDarkMode(sharedPreferences);
setupVisualIndicator(sentryManager, this);
} catch (Exception e) {
sentryManager.captureException(e);
}


RecyclerView recyclerView = findViewById(R.id.permissionRecyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));

List<PermissionInfo> permissions = getPermissionsList(sentryManager);
PermissionsAdapter adapter = new PermissionsAdapter(permissions);
recyclerView.setAdapter(adapter);
}

private void setupToolbar() {
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(false);
}
ImageView imageView = findViewById(R.id.connectionStatus);
imageView.setOnClickListener(v -> startActivity(new Intent(this, StatusActivity.class)));
}

/** @noinspection deprecation*/
private void setupLanguage() {
Resources resources = getResources();
Configuration configuration = resources.getConfiguration();
Locale appLocale = configuration.getLocales().get(0);
if (appLocale != null) {
Locale.setDefault(appLocale);
configuration.setLocale(appLocale);
resources.updateConfiguration(configuration, resources.getDisplayMetrics());
}
}

private void setupDarkMode(SharedPreferences sharedPreferences) {
String darkModeOverride = sharedPreferences.getString("darkmode_override", "match");
if (darkModeOverride.contains("match")) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
} else if (darkModeOverride.contains("on")) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
}

private void setupVisualIndicator(SentryManager sentryManager, LifecycleOwner lifecycleOwner) {
try {
new VisualIndicator(this).initiateVisualIndicator(this, lifecycleOwner, this);
} catch (Exception e) {
sentryManager.captureException(e);
}
}

private List<PermissionInfo> getPermissionsList(SentryManager sentryManager) {
List<PermissionInfo> permissions = new ArrayList<>();
try {
PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_PERMISSIONS);

if (packageInfo.requestedPermissions != null) {
for (String permission : packageInfo.requestedPermissions) {
PermissionInfo permissionInfo = getPackageManager().getPermissionInfo(permission, 0);
permissions.add(permissionInfo);
}
}
} catch (PackageManager.NameNotFoundException e) {
sentryManager.captureException(e);
}
return permissions;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_back_only, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.back) {
Intent mainIntent = new Intent(this, SettingsActivity.class);
startActivity(mainIntent);
}
return super.onContextItemSelected(item);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ protected void onCreate(Bundle savedInstanceState) {
SharedPreferences sharedPreferences = this.getSharedPreferences("preferences", Context.MODE_PRIVATE);
try {
if (sentryManager.isSentryEnabled()) {
SentryInitializer sentryInitializer = new SentryInitializer();
sentryInitializer.execute(this);
SentryInitializer.initialize(this);
}
setupToolbar();
setupLanguage();
Expand All @@ -62,6 +61,7 @@ private void setupToolbar() {
Objects.requireNonNull(getSupportActionBar()).setDisplayShowTitleEnabled(false);
}

/** @noinspection deprecation*/
private void setupLanguage() {
Resources resources = getResources();
Configuration configuration = resources.getConfiguration();
Expand Down Expand Up @@ -100,11 +100,9 @@ public void setupWebView(String url) {
webSettings.setDomStorageEnabled(true);
webSettings.setDatabaseEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
webSettings.setAllowFileAccess(false);
webSettings.setAllowContentAccess(false);
webSettings.setAllowUniversalAccessFromFileURLs(false);
webSettings.setSaveFormData(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl(url);
}
Expand Down
Loading