2020-01-25 10:25:02 +01:00
|
|
|
package app.fedilab.nitterizeme;
|
|
|
|
/* Copyright 2020 Thomas Schneider
|
|
|
|
*
|
|
|
|
* This file is a part of NitterizeMe
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* NitterizeMe is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with NitterizeMe; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
2020-02-18 12:25:20 +01:00
|
|
|
|
2020-01-25 11:00:55 +01:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
2020-01-25 15:38:39 +01:00
|
|
|
import android.content.pm.ActivityInfo;
|
|
|
|
import android.content.pm.ApplicationInfo;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.content.pm.ResolveInfo;
|
|
|
|
import android.net.Uri;
|
2020-01-25 10:25:02 +01:00
|
|
|
import android.os.Bundle;
|
2020-02-05 17:45:18 +01:00
|
|
|
import android.provider.Settings;
|
2020-01-25 10:25:02 +01:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
2020-01-25 11:00:55 +01:00
|
|
|
import android.view.View;
|
|
|
|
import android.widget.Button;
|
2020-02-17 15:34:09 +01:00
|
|
|
import android.widget.CheckBox;
|
2020-02-17 13:59:11 +01:00
|
|
|
import android.widget.ImageButton;
|
2020-02-17 15:34:09 +01:00
|
|
|
import android.widget.TextView;
|
2020-01-25 11:00:55 +01:00
|
|
|
|
2020-02-18 12:25:20 +01:00
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.appcompat.widget.SwitchCompat;
|
|
|
|
import androidx.appcompat.widget.Toolbar;
|
2020-02-28 09:33:49 +01:00
|
|
|
import androidx.constraintlayout.widget.Group;
|
2020-02-18 12:25:20 +01:00
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
2020-01-28 18:54:19 +01:00
|
|
|
|
2020-01-25 11:00:55 +01:00
|
|
|
import com.google.android.material.snackbar.Snackbar;
|
|
|
|
import com.google.android.material.textfield.TextInputEditText;
|
|
|
|
|
2020-01-25 15:38:39 +01:00
|
|
|
import java.util.ArrayList;
|
2020-01-25 11:00:55 +01:00
|
|
|
import java.util.Objects;
|
2020-01-25 10:25:02 +01:00
|
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity {
|
|
|
|
|
2020-02-18 12:25:20 +01:00
|
|
|
public static final String APP_PREFS = "app_prefs";
|
2020-01-25 10:25:02 +01:00
|
|
|
@SuppressWarnings("unused")
|
|
|
|
public static String TAG = "NitterizeMe";
|
2020-02-28 09:33:49 +01:00
|
|
|
public static final String SET_NITTER_HOST = "set_nitter_host";
|
2020-02-18 12:25:20 +01:00
|
|
|
public static String DEFAULT_NITTER_HOST = "nitter.net";
|
2020-02-28 09:33:49 +01:00
|
|
|
public static final String SET_INVIDIOUS_HOST = "set_invidious_host";
|
2020-02-18 12:25:20 +01:00
|
|
|
public static String DEFAULT_INVIDIOUS_HOST = "invidio.us";
|
|
|
|
public static String SET_INVIDIOUS_ENABLED = "set_invidious_enabled";
|
|
|
|
public static String SET_NITTER_ENABLED = "set_nitter_enabled";
|
|
|
|
public static String SET_OSM_ENABLED = "set_osm_enabled";
|
2020-02-28 09:33:49 +01:00
|
|
|
public static final String SET_OSM_HOST = "set_osm_host";
|
2020-02-18 12:25:20 +01:00
|
|
|
public static String DEFAULT_OSM_HOST = "www.openstreetmap.org";
|
2020-02-19 08:37:39 +01:00
|
|
|
public static String SET_BIBLIOGRAM_ENABLED = "set_bibliogram_enabled";
|
2020-02-28 09:33:49 +01:00
|
|
|
public static final String SET_BIBLIOGRAM_HOST = "set_bibliogram_host";
|
2020-02-19 08:37:39 +01:00
|
|
|
public static String DEFAULT_BIBLIOGRAM_HOST = "bibliogram.art";
|
2020-02-18 12:25:20 +01:00
|
|
|
public static String SET_GEO_URIS = "set_geo_uris";
|
2020-01-25 15:38:39 +01:00
|
|
|
//Supported domains
|
2020-02-18 08:56:43 +01:00
|
|
|
public static String[] twitter_domains = {
|
2020-01-25 15:38:39 +01:00
|
|
|
"twitter.com",
|
|
|
|
"mobile.twitter.com",
|
|
|
|
"www.twitter.com",
|
2020-02-18 08:56:43 +01:00
|
|
|
};
|
2020-02-19 08:37:39 +01:00
|
|
|
public static String[] instagram_domains = {
|
|
|
|
"instagram.com",
|
|
|
|
"www.instagram.com",
|
|
|
|
"m.instagram.com",
|
|
|
|
};
|
2020-02-18 08:56:43 +01:00
|
|
|
public static String[] youtube_domains = {
|
2020-01-25 15:38:39 +01:00
|
|
|
"www.youtube.com",
|
|
|
|
"youtube.com",
|
|
|
|
"m.youtube.com",
|
|
|
|
"youtu.be",
|
2020-02-17 17:32:28 +01:00
|
|
|
"youtube-nocookie.com"
|
2020-01-25 15:38:39 +01:00
|
|
|
};
|
2020-02-18 08:56:43 +01:00
|
|
|
public static String[] shortener_domains = {
|
|
|
|
"t.co",
|
|
|
|
"nyti.ms",
|
|
|
|
"bit.ly",
|
|
|
|
"tinyurl.com",
|
|
|
|
"goo.gl",
|
|
|
|
};
|
2020-02-18 12:25:20 +01:00
|
|
|
private AppInfoAdapter appInfoAdapter;
|
|
|
|
private RecyclerView list_apps;
|
|
|
|
private String[] domains;
|
2020-02-18 08:56:43 +01:00
|
|
|
|
2020-02-28 09:33:49 +01:00
|
|
|
private String nitterHost;
|
|
|
|
private String invidiousHost;
|
|
|
|
private String bibliogramHost;
|
|
|
|
private String osmHost;
|
|
|
|
|
2020-01-25 10:25:02 +01:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
|
|
|
setSupportActionBar(toolbar);
|
2020-01-25 11:00:55 +01:00
|
|
|
Objects.requireNonNull(getSupportActionBar()).setDisplayShowHomeEnabled(true);
|
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
2020-02-19 08:52:36 +01:00
|
|
|
domains = new String[twitter_domains.length + youtube_domains.length + shortener_domains.length + instagram_domains.length];
|
2020-02-18 08:56:43 +01:00
|
|
|
int i = 0;
|
2020-02-18 12:25:20 +01:00
|
|
|
for (String host : twitter_domains) {
|
2020-02-18 08:56:43 +01:00
|
|
|
domains[i] = host;
|
|
|
|
i++;
|
|
|
|
}
|
2020-02-18 12:25:20 +01:00
|
|
|
for (String host : youtube_domains) {
|
2020-02-18 08:56:43 +01:00
|
|
|
domains[i] = host;
|
|
|
|
i++;
|
|
|
|
}
|
2020-02-18 12:25:20 +01:00
|
|
|
for (String host : shortener_domains) {
|
2020-02-18 08:56:43 +01:00
|
|
|
domains[i] = host;
|
|
|
|
i++;
|
|
|
|
}
|
2020-02-19 08:37:39 +01:00
|
|
|
for (String host : instagram_domains) {
|
|
|
|
domains[i] = host;
|
|
|
|
i++;
|
|
|
|
}
|
2020-02-18 08:56:43 +01:00
|
|
|
|
2020-01-25 11:00:55 +01:00
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
|
2020-01-25 10:25:02 +01:00
|
|
|
|
2020-02-28 09:33:49 +01:00
|
|
|
TextView current_instance_nitter = findViewById(R.id.current_instance_nitter);
|
|
|
|
TextView current_instance_invidious = findViewById(R.id.current_instance_invidious);
|
|
|
|
TextView current_instance_bibliogram = findViewById(R.id.current_instance_bibliogram);
|
|
|
|
TextView current_instance_osm = findViewById(R.id.current_instance_osm);
|
|
|
|
|
|
|
|
|
2020-01-25 11:00:55 +01:00
|
|
|
TextInputEditText nitter_instance = findViewById(R.id.nitter_instance);
|
|
|
|
TextInputEditText invidious_instance = findViewById(R.id.invidious_instance);
|
2020-02-19 08:37:39 +01:00
|
|
|
TextInputEditText bibliogram_instance = findViewById(R.id.bibliogram_instance);
|
2020-02-02 19:12:04 +01:00
|
|
|
TextInputEditText osm_instance = findViewById(R.id.osm_instance);
|
2020-01-28 18:54:19 +01:00
|
|
|
|
2020-02-20 15:25:41 +01:00
|
|
|
|
2020-02-28 09:33:49 +01:00
|
|
|
Group invidious_current_group = findViewById(R.id.group_current_invidious);
|
|
|
|
Group nitter_current_group = findViewById(R.id.group_current_nitter);
|
|
|
|
Group bibliogram_current_group = findViewById(R.id.group_current_bibliogram);
|
|
|
|
Group osm_current_group = findViewById(R.id.group_current_osm);
|
|
|
|
|
|
|
|
|
|
|
|
Group invidious_custom_group = findViewById(R.id.group_custom_invidious);
|
|
|
|
Group nitter_custom_group = findViewById(R.id.group_custom_nitter);
|
|
|
|
Group bibliogram_custom_group = findViewById(R.id.group_custom_bibliogram);
|
|
|
|
Group osm_custom_group = findViewById(R.id.group_custom_osm);
|
2020-02-20 15:25:41 +01:00
|
|
|
|
|
|
|
|
2020-01-28 18:54:19 +01:00
|
|
|
SwitchCompat enable_nitter = findViewById(R.id.enable_nitter);
|
|
|
|
SwitchCompat enable_invidious = findViewById(R.id.enable_invidious);
|
2020-02-19 08:37:39 +01:00
|
|
|
SwitchCompat enable_bibliogram = findViewById(R.id.enable_bibliogram);
|
2020-01-29 12:58:26 +01:00
|
|
|
SwitchCompat enable_osm = findViewById(R.id.enable_osm);
|
2020-01-28 18:54:19 +01:00
|
|
|
|
2020-02-28 09:33:49 +01:00
|
|
|
|
|
|
|
ImageButton expand_instance_nitter = findViewById(R.id.button_expand_instance_nitter);
|
|
|
|
ImageButton expand_instance_invidious = findViewById(R.id.button_expand_instance_invidious);
|
|
|
|
ImageButton expand_instance_bibliogram = findViewById(R.id.button_expand_instance_bibliogram);
|
|
|
|
ImageButton expand_instance_osm = findViewById(R.id.button_expand_instance_osm);
|
|
|
|
|
|
|
|
|
2020-01-28 18:54:19 +01:00
|
|
|
boolean nitter_enabled = sharedpreferences.getBoolean(SET_NITTER_ENABLED, true);
|
|
|
|
boolean invidious_enabled = sharedpreferences.getBoolean(SET_INVIDIOUS_ENABLED, true);
|
2020-01-29 12:58:26 +01:00
|
|
|
boolean osm_enabled = sharedpreferences.getBoolean(SET_OSM_ENABLED, true);
|
2020-02-19 08:37:39 +01:00
|
|
|
boolean bibliogram_enabled = sharedpreferences.getBoolean(SET_BIBLIOGRAM_ENABLED, true);
|
2020-02-20 15:25:41 +01:00
|
|
|
boolean geouri_enabled = sharedpreferences.getBoolean(SET_GEO_URIS, false);
|
2020-01-28 18:54:19 +01:00
|
|
|
|
|
|
|
enable_nitter.setChecked(nitter_enabled);
|
|
|
|
enable_invidious.setChecked(invidious_enabled);
|
2020-02-19 08:37:39 +01:00
|
|
|
enable_bibliogram.setChecked(bibliogram_enabled);
|
2020-01-29 12:58:26 +01:00
|
|
|
enable_osm.setChecked(osm_enabled);
|
2020-01-28 18:54:19 +01:00
|
|
|
|
2020-02-28 09:33:49 +01:00
|
|
|
ImageButton save_instance_nitter = findViewById(R.id.button_save_instance_nitter);
|
|
|
|
ImageButton save_instance_invidious = findViewById(R.id.button_save_instance_invidious);
|
|
|
|
ImageButton save_instance_bibliogram = findViewById(R.id.button_save_instance_bibliogram);
|
|
|
|
ImageButton save_instance_osm = findViewById(R.id.button_save_instance_osm);
|
|
|
|
|
2020-02-20 11:20:30 +01:00
|
|
|
CheckBox enable_geo_uris = findViewById(R.id.enable_geo_uris);
|
2020-02-17 13:59:11 +01:00
|
|
|
list_apps = findViewById(R.id.list_apps);
|
2020-02-28 09:33:49 +01:00
|
|
|
nitterHost = sharedpreferences.getString(SET_NITTER_HOST, null);
|
|
|
|
invidiousHost = sharedpreferences.getString(SET_INVIDIOUS_HOST, null);
|
|
|
|
bibliogramHost = sharedpreferences.getString(SET_BIBLIOGRAM_HOST, null);
|
|
|
|
osmHost = sharedpreferences.getString(SET_OSM_HOST, null);
|
2020-01-28 18:54:19 +01:00
|
|
|
|
2020-02-28 09:33:49 +01:00
|
|
|
invidious_current_group.setVisibility(invidious_enabled ? View.VISIBLE : View.GONE);
|
|
|
|
nitter_current_group.setVisibility(nitter_enabled ? View.VISIBLE : View.GONE);
|
|
|
|
bibliogram_current_group.setVisibility(bibliogram_enabled ? View.VISIBLE : View.GONE);
|
|
|
|
osm_current_group.setVisibility((osm_enabled && geouri_enabled) ? View.VISIBLE : View.GONE);
|
|
|
|
enable_geo_uris.setVisibility(osm_enabled ? View.VISIBLE : View.GONE);
|
2020-02-20 15:25:41 +01:00
|
|
|
|
2020-01-28 18:54:19 +01:00
|
|
|
enable_invidious.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putBoolean(SET_INVIDIOUS_ENABLED, isChecked);
|
|
|
|
editor.apply();
|
2020-02-28 09:33:49 +01:00
|
|
|
invidious_current_group.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
|
|
|
invidious_custom_group.setVisibility(View.GONE);
|
|
|
|
expand_instance_invidious.setRotation(0);
|
2020-01-28 18:54:19 +01:00
|
|
|
});
|
|
|
|
enable_nitter.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putBoolean(SET_NITTER_ENABLED, isChecked);
|
|
|
|
editor.apply();
|
2020-02-28 09:33:49 +01:00
|
|
|
nitter_current_group.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
|
|
|
nitter_custom_group.setVisibility(View.GONE);
|
|
|
|
expand_instance_nitter.setRotation(0);
|
2020-01-28 18:54:19 +01:00
|
|
|
});
|
2020-02-19 08:37:39 +01:00
|
|
|
enable_bibliogram.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putBoolean(SET_BIBLIOGRAM_ENABLED, isChecked);
|
|
|
|
editor.apply();
|
2020-02-28 09:33:49 +01:00
|
|
|
bibliogram_current_group.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
|
|
|
bibliogram_custom_group.setVisibility(View.GONE);
|
|
|
|
expand_instance_bibliogram.setRotation(0);
|
2020-02-19 08:37:39 +01:00
|
|
|
});
|
2020-01-29 12:58:26 +01:00
|
|
|
enable_osm.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putBoolean(SET_OSM_ENABLED, isChecked);
|
|
|
|
editor.apply();
|
2020-02-28 09:33:49 +01:00
|
|
|
osm_current_group.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
|
|
|
osm_custom_group.setVisibility(View.GONE);
|
2020-02-20 15:25:41 +01:00
|
|
|
enable_geo_uris.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
2020-02-28 09:33:49 +01:00
|
|
|
expand_instance_osm.setRotation(0);
|
2020-02-20 15:25:41 +01:00
|
|
|
boolean geo = sharedpreferences.getBoolean(SET_GEO_URIS, false);
|
2020-02-28 09:33:49 +01:00
|
|
|
if (isChecked) {
|
|
|
|
if (geo) {
|
|
|
|
osm_current_group.setVisibility(View.GONE);
|
|
|
|
osm_custom_group.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
osm_current_group.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expand_instance_nitter.setOnClickListener(v -> {
|
|
|
|
boolean custom_instance_visibility = nitter_custom_group.getVisibility() == View.VISIBLE;
|
|
|
|
if (custom_instance_visibility) {
|
|
|
|
expand_instance_nitter.setRotation(0f);
|
|
|
|
nitter_custom_group.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
expand_instance_nitter.setRotation(180f);
|
|
|
|
nitter_custom_group.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nitterHost != null) {
|
|
|
|
nitter_instance.setText(nitterHost);
|
|
|
|
} else {
|
|
|
|
nitter_instance.setText("");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
expand_instance_invidious.setOnClickListener(v -> {
|
|
|
|
boolean custom_instance_visibility = invidious_custom_group.getVisibility() == View.VISIBLE;
|
|
|
|
if (custom_instance_visibility) {
|
|
|
|
expand_instance_invidious.setRotation(0f);
|
|
|
|
invidious_custom_group.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
expand_instance_invidious.setRotation(180f);
|
|
|
|
invidious_custom_group.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (invidiousHost != null) {
|
|
|
|
invidious_instance.setText(invidiousHost);
|
|
|
|
} else {
|
|
|
|
invidious_instance.setText("");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
expand_instance_bibliogram.setOnClickListener(v -> {
|
|
|
|
boolean custom_instance_visibility = bibliogram_custom_group.getVisibility() == View.VISIBLE;
|
|
|
|
if (custom_instance_visibility) {
|
|
|
|
expand_instance_bibliogram.setRotation(0f);
|
|
|
|
bibliogram_custom_group.setVisibility(View.GONE);
|
2020-02-20 15:25:41 +01:00
|
|
|
} else {
|
2020-02-28 09:33:49 +01:00
|
|
|
expand_instance_bibliogram.setRotation(180f);
|
|
|
|
bibliogram_custom_group.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bibliogramHost != null) {
|
|
|
|
bibliogram_instance.setText(bibliogramHost);
|
|
|
|
} else {
|
|
|
|
bibliogram_instance.setText("");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
expand_instance_osm.setOnClickListener(v -> {
|
|
|
|
boolean custom_instance_visibility = osm_custom_group.getVisibility() == View.VISIBLE;
|
|
|
|
if (custom_instance_visibility) {
|
|
|
|
expand_instance_osm.setRotation(0f);
|
|
|
|
osm_custom_group.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
expand_instance_osm.setRotation(180f);
|
|
|
|
osm_custom_group.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (osmHost != null) {
|
|
|
|
osm_instance.setText(osmHost);
|
|
|
|
} else {
|
|
|
|
osm_instance.setText("");
|
2020-02-20 15:25:41 +01:00
|
|
|
}
|
2020-01-29 12:58:26 +01:00
|
|
|
});
|
2020-01-28 18:54:19 +01:00
|
|
|
|
2020-02-28 09:33:49 +01:00
|
|
|
|
|
|
|
|
2020-02-18 12:25:20 +01:00
|
|
|
if (nitterHost != null) {
|
2020-01-25 11:00:55 +01:00
|
|
|
nitter_instance.setText(nitterHost);
|
2020-02-28 09:33:49 +01:00
|
|
|
current_instance_nitter.setText(nitterHost);
|
|
|
|
} else {
|
|
|
|
current_instance_nitter.setText(DEFAULT_NITTER_HOST);
|
2020-01-25 11:00:55 +01:00
|
|
|
}
|
2020-02-18 12:25:20 +01:00
|
|
|
if (invidiousHost != null) {
|
2020-01-25 11:00:55 +01:00
|
|
|
invidious_instance.setText(invidiousHost);
|
2020-02-28 09:33:49 +01:00
|
|
|
current_instance_invidious.setText(invidiousHost);
|
|
|
|
} else {
|
|
|
|
current_instance_invidious.setText(DEFAULT_INVIDIOUS_HOST);
|
2020-01-25 11:00:55 +01:00
|
|
|
}
|
2020-02-19 08:37:39 +01:00
|
|
|
if (bibliogramHost != null) {
|
|
|
|
bibliogram_instance.setText(bibliogramHost);
|
2020-02-28 09:33:49 +01:00
|
|
|
current_instance_bibliogram.setText(bibliogramHost);
|
|
|
|
} else {
|
|
|
|
current_instance_bibliogram.setText(DEFAULT_BIBLIOGRAM_HOST);
|
2020-02-19 08:37:39 +01:00
|
|
|
}
|
2020-02-18 12:25:20 +01:00
|
|
|
if (osmHost != null) {
|
2020-02-02 19:12:04 +01:00
|
|
|
osm_instance.setText(osmHost);
|
2020-02-28 09:33:49 +01:00
|
|
|
current_instance_osm.setText(osmHost);
|
|
|
|
} else {
|
|
|
|
current_instance_osm.setText(DEFAULT_OSM_HOST);
|
2020-02-02 19:12:04 +01:00
|
|
|
}
|
2020-02-20 15:25:41 +01:00
|
|
|
enable_geo_uris.setChecked(geouri_enabled);
|
|
|
|
if (geouri_enabled) {
|
2020-02-28 09:33:49 +01:00
|
|
|
osm_current_group.setVisibility(View.GONE);
|
|
|
|
osm_custom_group.setVisibility(View.GONE);
|
2020-02-20 15:25:41 +01:00
|
|
|
} else {
|
2020-02-28 09:33:49 +01:00
|
|
|
osm_current_group.setVisibility(View.VISIBLE);
|
2020-02-20 15:25:41 +01:00
|
|
|
}
|
|
|
|
|
2020-02-28 09:33:49 +01:00
|
|
|
save_instance_nitter.setOnClickListener(v -> {
|
2020-01-25 11:00:55 +01:00
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
if (nitter_instance.getText() != null && nitter_instance.getText().toString().trim().length() > 0) {
|
2020-02-28 09:33:49 +01:00
|
|
|
String custom_instance = nitter_instance.getText().toString().toLowerCase().trim();
|
|
|
|
editor.putString(SET_NITTER_HOST, custom_instance);
|
|
|
|
current_instance_nitter.setText(custom_instance);
|
2020-01-25 11:00:55 +01:00
|
|
|
} else {
|
|
|
|
editor.putString(SET_NITTER_HOST, null);
|
2020-02-28 09:33:49 +01:00
|
|
|
current_instance_nitter.setText(DEFAULT_NITTER_HOST);
|
2020-01-25 11:00:55 +01:00
|
|
|
}
|
2020-02-28 09:33:49 +01:00
|
|
|
editor.apply();
|
|
|
|
});
|
|
|
|
save_instance_invidious.setOnClickListener(v -> {
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
2020-01-25 11:00:55 +01:00
|
|
|
if (invidious_instance.getText() != null && invidious_instance.getText().toString().trim().length() > 0) {
|
2020-02-28 09:33:49 +01:00
|
|
|
String custom_instance = invidious_instance.getText().toString().toLowerCase().trim();
|
|
|
|
editor.putString(SET_INVIDIOUS_HOST, custom_instance);
|
|
|
|
current_instance_invidious.setText(custom_instance);
|
2020-01-25 11:00:55 +01:00
|
|
|
} else {
|
|
|
|
editor.putString(SET_INVIDIOUS_HOST, null);
|
2020-02-28 09:33:49 +01:00
|
|
|
current_instance_invidious.setText(DEFAULT_INVIDIOUS_HOST);
|
2020-01-25 11:00:55 +01:00
|
|
|
}
|
2020-02-28 09:33:49 +01:00
|
|
|
editor.apply();
|
|
|
|
});
|
|
|
|
save_instance_bibliogram.setOnClickListener(v -> {
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
2020-02-19 08:37:39 +01:00
|
|
|
if (bibliogram_instance.getText() != null && bibliogram_instance.getText().toString().trim().length() > 0) {
|
2020-02-28 09:33:49 +01:00
|
|
|
String custom_instance = bibliogram_instance.getText().toString().toLowerCase().trim();
|
|
|
|
editor.putString(SET_BIBLIOGRAM_HOST, custom_instance);
|
|
|
|
current_instance_bibliogram.setText(custom_instance);
|
2020-02-19 08:37:39 +01:00
|
|
|
} else {
|
|
|
|
editor.putString(SET_BIBLIOGRAM_HOST, null);
|
2020-02-28 09:33:49 +01:00
|
|
|
current_instance_bibliogram.setText(DEFAULT_BIBLIOGRAM_HOST);
|
2020-02-19 08:37:39 +01:00
|
|
|
}
|
2020-02-28 09:33:49 +01:00
|
|
|
editor.apply();
|
|
|
|
});
|
|
|
|
save_instance_osm.setOnClickListener(v -> {
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
2020-02-02 19:12:04 +01:00
|
|
|
if (osm_instance.getText() != null && osm_instance.getText().toString().trim().length() > 0) {
|
2020-02-28 09:33:49 +01:00
|
|
|
String custom_instance = osm_instance.getText().toString().toLowerCase().trim();
|
|
|
|
editor.putString(SET_OSM_HOST, custom_instance);
|
2020-02-02 19:12:04 +01:00
|
|
|
} else {
|
|
|
|
editor.putString(SET_OSM_HOST, null);
|
2020-02-28 09:33:49 +01:00
|
|
|
current_instance_osm.setText(DEFAULT_OSM_HOST);
|
2020-02-02 19:12:04 +01:00
|
|
|
}
|
2020-01-25 11:00:55 +01:00
|
|
|
editor.apply();
|
|
|
|
});
|
2020-01-25 15:38:39 +01:00
|
|
|
|
2020-02-05 17:45:18 +01:00
|
|
|
Button configure = findViewById(R.id.configure);
|
|
|
|
configure.setOnClickListener(v -> {
|
|
|
|
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
|
|
|
Uri uri = Uri.fromParts("package", getApplicationInfo().packageName, null);
|
|
|
|
intent.setData(uri);
|
|
|
|
startActivity(intent);
|
|
|
|
});
|
|
|
|
|
2020-02-17 13:59:11 +01:00
|
|
|
ImageButton buttonExpand = findViewById(R.id.button_expand);
|
|
|
|
buttonExpand.setOnClickListener(v -> {
|
2020-02-18 12:25:20 +01:00
|
|
|
if (list_apps.getVisibility() == View.VISIBLE) {
|
2020-02-17 13:59:11 +01:00
|
|
|
list_apps.setVisibility(View.GONE);
|
|
|
|
buttonExpand.setContentDescription(getString(R.string.display_supported_links));
|
2020-02-20 11:20:30 +01:00
|
|
|
buttonExpand.setImageResource(R.drawable.ic_expand_more);
|
2020-02-18 12:25:20 +01:00
|
|
|
} else {
|
2020-02-17 13:59:11 +01:00
|
|
|
list_apps.setVisibility(View.VISIBLE);
|
|
|
|
buttonExpand.setContentDescription(getString(R.string.hide_supported_links));
|
2020-02-20 11:20:30 +01:00
|
|
|
buttonExpand.setImageResource(R.drawable.ic_expand_less);
|
2020-02-17 13:59:11 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-02-20 11:20:30 +01:00
|
|
|
ImageButton buttonPing = findViewById(R.id.instances);
|
|
|
|
buttonPing.setOnClickListener(v -> {
|
|
|
|
Intent intent = new Intent(MainActivity.this, InstanceActivity.class);
|
|
|
|
startActivity(intent);
|
|
|
|
});
|
2020-01-25 15:38:39 +01:00
|
|
|
ArrayList<AppInfo> appInfos = new ArrayList<>();
|
2020-02-18 12:25:20 +01:00
|
|
|
for (String domain : domains) {
|
2020-01-25 15:38:39 +01:00
|
|
|
AppInfo appInfo = new AppInfo();
|
|
|
|
appInfo.setDomain(domain);
|
2020-02-18 12:25:20 +01:00
|
|
|
appInfo.setApplicationInfo(getDefaultApp("https://" + domain));
|
2020-01-25 15:38:39 +01:00
|
|
|
appInfos.add(appInfo);
|
|
|
|
}
|
|
|
|
|
2020-02-20 11:20:30 +01:00
|
|
|
|
2020-02-17 15:34:09 +01:00
|
|
|
enable_geo_uris.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putBoolean(SET_GEO_URIS, isChecked);
|
|
|
|
editor.apply();
|
|
|
|
TextView osm_indications = findViewById(R.id.osm_indications);
|
2020-02-18 12:25:20 +01:00
|
|
|
if (isChecked) {
|
2020-02-28 09:33:49 +01:00
|
|
|
osm_current_group.setVisibility(View.GONE);
|
|
|
|
osm_custom_group.setVisibility(View.GONE);
|
2020-02-17 15:34:09 +01:00
|
|
|
osm_indications.setText(R.string.redirect_gm_to_geo_uri);
|
2020-02-18 12:25:20 +01:00
|
|
|
} else {
|
2020-02-28 09:33:49 +01:00
|
|
|
osm_current_group.setVisibility(View.VISIBLE);
|
2020-02-17 15:34:09 +01:00
|
|
|
osm_indications.setText(R.string.redirect_gm_to_osm);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-02-28 09:33:49 +01:00
|
|
|
sharedpreferences.registerOnSharedPreferenceChangeListener(
|
|
|
|
(sharedPreferences, key) -> {
|
|
|
|
switch (key) {
|
|
|
|
case SET_NITTER_HOST:
|
|
|
|
nitterHost = sharedpreferences.getString(SET_NITTER_HOST, null);
|
|
|
|
nitter_custom_group.setVisibility(View.GONE);
|
|
|
|
if (nitterHost != null && nitterHost.trim().length() > 0)
|
|
|
|
current_instance_nitter.setText(nitterHost);
|
|
|
|
else
|
|
|
|
current_instance_nitter.setText(DEFAULT_NITTER_HOST);
|
|
|
|
expand_instance_nitter.setRotation(0f);
|
|
|
|
break;
|
|
|
|
case SET_INVIDIOUS_HOST:
|
|
|
|
invidiousHost = sharedpreferences.getString(SET_INVIDIOUS_HOST, null);
|
|
|
|
invidious_custom_group.setVisibility(View.GONE);
|
|
|
|
if (invidiousHost != null && invidiousHost.trim().length() > 0)
|
|
|
|
current_instance_invidious.setText(invidiousHost);
|
|
|
|
else
|
|
|
|
current_instance_invidious.setText(DEFAULT_INVIDIOUS_HOST);
|
|
|
|
expand_instance_invidious.setRotation(0f);
|
|
|
|
break;
|
|
|
|
case SET_BIBLIOGRAM_HOST:
|
|
|
|
bibliogramHost = sharedpreferences.getString(SET_BIBLIOGRAM_HOST, null);
|
|
|
|
bibliogram_custom_group.setVisibility(View.GONE);
|
|
|
|
if (bibliogramHost != null && bibliogramHost.trim().length() > 0)
|
|
|
|
current_instance_bibliogram.setText(bibliogramHost);
|
|
|
|
else
|
|
|
|
current_instance_bibliogram.setText(DEFAULT_BIBLIOGRAM_HOST);
|
|
|
|
expand_instance_bibliogram.setRotation(0f);
|
|
|
|
break;
|
|
|
|
case SET_OSM_HOST:
|
|
|
|
osmHost = sharedpreferences.getString(SET_OSM_HOST, null);
|
|
|
|
osm_custom_group.setVisibility(View.GONE);
|
|
|
|
if (osmHost != null && osmHost.trim().length() > 0)
|
|
|
|
current_instance_osm.setText(osmHost);
|
|
|
|
else
|
|
|
|
current_instance_osm.setText(DEFAULT_OSM_HOST);
|
|
|
|
expand_instance_osm.setRotation(0f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key.equals(SET_NITTER_HOST) || key.equals(SET_INVIDIOUS_HOST) || key.equals(SET_BIBLIOGRAM_HOST) || key.equals(SET_OSM_HOST)) {
|
|
|
|
View parentLayout = findViewById(android.R.id.content);
|
|
|
|
Snackbar.make(parentLayout, R.string.instances_saved, Snackbar.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2020-02-05 17:45:18 +01:00
|
|
|
appInfoAdapter = new AppInfoAdapter(appInfos);
|
2020-01-25 15:38:39 +01:00
|
|
|
list_apps.setAdapter(appInfoAdapter);
|
|
|
|
final LinearLayoutManager mLayoutManager;
|
|
|
|
mLayoutManager = new LinearLayoutManager(MainActivity.this);
|
|
|
|
list_apps.setLayoutManager(mLayoutManager);
|
2020-01-25 16:22:40 +01:00
|
|
|
list_apps.setNestedScrollingEnabled(false);
|
2020-01-25 15:38:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allow to get info about application that opens the link by default
|
2020-02-18 12:25:20 +01:00
|
|
|
*
|
2020-01-25 15:38:39 +01:00
|
|
|
* @param url String url for test
|
|
|
|
* @return ApplicationInfo info about the application
|
|
|
|
*/
|
|
|
|
ApplicationInfo getDefaultApp(String url) {
|
|
|
|
final Intent browserIntent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
|
browserIntent.setData(Uri.parse(url));
|
|
|
|
final ResolveInfo defaultResolution = getPackageManager().resolveActivity(browserIntent, PackageManager.MATCH_DEFAULT_ONLY);
|
|
|
|
if (defaultResolution != null) {
|
|
|
|
final ActivityInfo activity = defaultResolution.activityInfo;
|
2020-01-25 16:22:40 +01:00
|
|
|
if (!activity.name.equals("com.android.internal.app.ResolverActivity") && !activity.packageName.equals("com.huawei.android.internal.app")) {
|
2020-01-25 15:38:39 +01:00
|
|
|
return activity.applicationInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2020-01-25 10:25:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
// Inflate the menu; this adds items to the action bar if it is present.
|
|
|
|
getMenuInflater().inflate(R.menu.menu_main, menu);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
// Handle action bar item clicks here. The action bar will
|
|
|
|
// automatically handle clicks on the Home/Up button, so long
|
|
|
|
// as you specify a parent activity in AndroidManifest.xml.
|
|
|
|
int id = item.getItemId();
|
|
|
|
|
|
|
|
//noinspection SimplifiableIfStatement
|
|
|
|
if (id == R.id.action_about) {
|
2020-01-25 11:00:55 +01:00
|
|
|
Intent intent = new Intent(MainActivity.this, AboutActivity.class);
|
|
|
|
startActivity(intent);
|
2020-01-25 10:25:02 +01:00
|
|
|
return true;
|
2020-02-18 12:25:20 +01:00
|
|
|
} else if (id == android.R.id.home) {
|
2020-01-25 11:00:55 +01:00
|
|
|
finish();
|
2020-01-25 10:25:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
2020-02-05 17:45:18 +01:00
|
|
|
|
|
|
|
@Override
|
2020-02-18 12:25:20 +01:00
|
|
|
protected void onResume() {
|
2020-02-05 17:45:18 +01:00
|
|
|
super.onResume();
|
2020-02-18 12:25:20 +01:00
|
|
|
if (list_apps != null) {
|
2020-02-17 13:59:11 +01:00
|
|
|
ArrayList<AppInfo> appInfos = new ArrayList<>();
|
2020-02-18 12:25:20 +01:00
|
|
|
for (String domain : domains) {
|
2020-02-17 13:59:11 +01:00
|
|
|
AppInfo appInfo = new AppInfo();
|
|
|
|
appInfo.setDomain(domain);
|
2020-02-18 12:25:20 +01:00
|
|
|
appInfo.setApplicationInfo(getDefaultApp("https://" + domain));
|
2020-02-17 13:59:11 +01:00
|
|
|
appInfos.add(appInfo);
|
|
|
|
}
|
|
|
|
appInfoAdapter = new AppInfoAdapter(appInfos);
|
|
|
|
list_apps.setAdapter(appInfoAdapter);
|
2020-02-05 17:45:18 +01:00
|
|
|
}
|
2020-02-20 12:10:39 +01:00
|
|
|
TextInputEditText nitter_instance = findViewById(R.id.nitter_instance);
|
|
|
|
TextInputEditText invidious_instance = findViewById(R.id.invidious_instance);
|
|
|
|
TextInputEditText bibliogram_instance = findViewById(R.id.bibliogram_instance);
|
|
|
|
SharedPreferences sharedpreferences = getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
|
|
|
|
String nitterHost = sharedpreferences.getString(SET_NITTER_HOST, null);
|
|
|
|
String invidiousHost = sharedpreferences.getString(SET_INVIDIOUS_HOST, null);
|
|
|
|
String bibliogramHost = sharedpreferences.getString(SET_BIBLIOGRAM_HOST, null);
|
|
|
|
if (nitterHost != null) {
|
|
|
|
nitter_instance.setText(nitterHost);
|
|
|
|
}
|
|
|
|
if (invidiousHost != null) {
|
|
|
|
invidious_instance.setText(invidiousHost);
|
|
|
|
}
|
|
|
|
if (bibliogramHost != null) {
|
|
|
|
bibliogram_instance.setText(bibliogramHost);
|
|
|
|
}
|
|
|
|
|
2020-02-05 17:45:18 +01:00
|
|
|
}
|
2020-01-25 10:25:02 +01:00
|
|
|
}
|