2020-04-15 17:51:18 +02:00
|
|
|
package app.fedilab.nitterizeme.activities;
|
2020-02-20 11:20:30 +01:00
|
|
|
/* Copyright 2020 Thomas Schneider
|
|
|
|
*
|
2020-04-10 17:25:19 +02:00
|
|
|
* This file is a part of UntrackMe
|
2020-02-20 11:20:30 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2020-04-10 17:25:19 +02:00
|
|
|
* UntrackMe is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
2020-02-20 11:20:30 +01:00
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
|
|
|
*
|
2020-04-10 17:25:19 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along with UntrackMe; if not,
|
2020-02-20 11:20:30 +01:00
|
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
|
2020-08-31 19:00:17 +02:00
|
|
|
|
2020-02-20 11:20:30 +01:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.Button;
|
2020-03-01 10:42:01 +01:00
|
|
|
import android.widget.ImageButton;
|
2020-02-20 11:20:30 +01:00
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.RelativeLayout;
|
2020-03-01 10:42:01 +01:00
|
|
|
import android.widget.TextView;
|
2020-02-20 11:20:30 +01:00
|
|
|
|
2020-03-01 10:42:01 +01:00
|
|
|
import androidx.appcompat.app.AlertDialog;
|
2020-02-20 11:20:30 +01:00
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
2020-08-31 19:00:17 +02:00
|
|
|
import androidx.lifecycle.ViewModelProvider;
|
2020-02-20 11:20:30 +01:00
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
2020-02-29 10:21:35 +01:00
|
|
|
import com.google.android.material.snackbar.Snackbar;
|
|
|
|
|
2020-02-20 11:20:30 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2020-04-15 17:51:18 +02:00
|
|
|
import app.fedilab.nitterizeme.R;
|
|
|
|
import app.fedilab.nitterizeme.adapters.InstanceAdapter;
|
|
|
|
import app.fedilab.nitterizeme.entities.Instance;
|
2020-08-31 19:00:17 +02:00
|
|
|
import app.fedilab.nitterizeme.viewmodels.SearchInstanceVM;
|
2020-04-15 17:51:18 +02:00
|
|
|
|
2020-02-20 12:10:39 +01:00
|
|
|
|
2020-02-20 11:20:30 +01:00
|
|
|
public class InstanceActivity extends AppCompatActivity {
|
|
|
|
|
2020-05-31 18:34:22 +02:00
|
|
|
private static String list_for_instances = "https://framagit.org/tom79/fedilab_app/-/blob/master/content/untrackme_instances/payload_2.json";
|
2020-09-22 18:09:49 +02:00
|
|
|
private static String list_for_bibliogram_instances = "https://bibliogram.art/api/instances";
|
2020-03-01 10:42:01 +01:00
|
|
|
|
2020-02-20 11:20:30 +01:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_popup_instance);
|
2020-04-15 18:29:06 +02:00
|
|
|
setTitle(R.string.select_instances);
|
2020-02-20 11:20:30 +01:00
|
|
|
|
2020-08-31 19:00:17 +02:00
|
|
|
SearchInstanceVM viewModel = new ViewModelProvider(this).get(SearchInstanceVM.class);
|
2020-09-07 18:57:06 +02:00
|
|
|
viewModel.getInstances().observe(this, result -> {
|
2020-08-31 19:00:17 +02:00
|
|
|
LinearLayout instance_container = findViewById(R.id.instance_container);
|
|
|
|
RelativeLayout loader = findViewById(R.id.loader);
|
|
|
|
RecyclerView invidious_instances = findViewById(R.id.invidious_instances);
|
|
|
|
RecyclerView nitter_instances = findViewById(R.id.nitter_instances);
|
|
|
|
RecyclerView bibliogram_instances = findViewById(R.id.bibliogram_instances);
|
|
|
|
Button latency_test = findViewById(R.id.latency_test);
|
|
|
|
ImageButton instance_info = findViewById(R.id.instance_info);
|
|
|
|
Button close = findViewById(R.id.close);
|
2020-02-29 11:07:38 +01:00
|
|
|
if (result == null) {
|
2020-08-31 19:00:17 +02:00
|
|
|
View parentLayout = findViewById(android.R.id.content);
|
|
|
|
Snackbar.make(parentLayout, R.string.error_message_internet, Snackbar.LENGTH_LONG).setAction(R.string.close, v -> finish()).show();
|
2020-02-29 10:21:35 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-08-31 19:00:17 +02:00
|
|
|
ArrayList<Instance> invidiousInstances = new ArrayList<>();
|
|
|
|
ArrayList<Instance> nitterInstances = new ArrayList<>();
|
|
|
|
ArrayList<Instance> bibliogramInstances = new ArrayList<>();
|
2020-09-06 18:55:06 +02:00
|
|
|
for (Instance instance : result) {
|
|
|
|
if (instance.getType() == Instance.instanceType.INVIDIOUS) {
|
2020-02-20 11:20:30 +01:00
|
|
|
invidiousInstances.add(instance);
|
2020-09-06 18:55:06 +02:00
|
|
|
} else if (instance.getType() == Instance.instanceType.NITTER) {
|
2020-02-20 11:20:30 +01:00
|
|
|
nitterInstances.add(instance);
|
2020-09-06 18:55:06 +02:00
|
|
|
} else if (instance.getType() == Instance.instanceType.BIBLIOGRAM) {
|
2020-02-20 11:20:30 +01:00
|
|
|
bibliogramInstances.add(instance);
|
|
|
|
}
|
|
|
|
}
|
2020-08-31 19:00:17 +02:00
|
|
|
final LinearLayoutManager iLayoutManager = new LinearLayoutManager(this);
|
|
|
|
InstanceAdapter invidiousAdapter = new InstanceAdapter(invidiousInstances);
|
|
|
|
invidious_instances.setAdapter(invidiousAdapter);
|
|
|
|
invidious_instances.setLayoutManager(iLayoutManager);
|
|
|
|
invidious_instances.setNestedScrollingEnabled(false);
|
|
|
|
|
|
|
|
final LinearLayoutManager nLayoutManager = new LinearLayoutManager(this);
|
|
|
|
InstanceAdapter nitterAdapter = new InstanceAdapter(nitterInstances);
|
|
|
|
nitter_instances.setAdapter(nitterAdapter);
|
|
|
|
nitter_instances.setLayoutManager(nLayoutManager);
|
|
|
|
nitter_instances.setNestedScrollingEnabled(false);
|
|
|
|
|
|
|
|
final LinearLayoutManager bLayoutManager = new LinearLayoutManager(this);
|
|
|
|
InstanceAdapter bibliogramAdapter = new InstanceAdapter(bibliogramInstances);
|
|
|
|
bibliogram_instances.setAdapter(bibliogramAdapter);
|
|
|
|
bibliogram_instances.setLayoutManager(bLayoutManager);
|
|
|
|
bibliogram_instances.setNestedScrollingEnabled(false);
|
|
|
|
latency_test.setOnClickListener(
|
|
|
|
v -> {
|
|
|
|
invidiousAdapter.evalLatency();
|
|
|
|
nitterAdapter.evalLatency();
|
|
|
|
bibliogramAdapter.evalLatency();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
instance_info.setOnClickListener(v -> {
|
|
|
|
AlertDialog.Builder instanceInfo = new AlertDialog.Builder(this);
|
|
|
|
instanceInfo.setTitle(R.string.about_instances_title);
|
|
|
|
View view = getLayoutInflater().inflate(R.layout.popup_instance_info, new LinearLayout(getApplicationContext()), false);
|
|
|
|
instanceInfo.setView(view);
|
|
|
|
TextView infoInstancesTextview = view.findViewById(R.id.info_instances);
|
|
|
|
infoInstancesTextview.setText(getString(R.string.about_instances, list_for_instances, list_for_instances));
|
|
|
|
instanceInfo.setPositiveButton(R.string.close, (dialog, id) -> dialog.dismiss());
|
|
|
|
AlertDialog alertDialog = instanceInfo.create();
|
|
|
|
alertDialog.show();
|
|
|
|
});
|
2020-02-20 11:20:30 +01:00
|
|
|
|
2020-08-31 19:00:17 +02:00
|
|
|
close.setOnClickListener(v -> finish());
|
2020-02-20 11:20:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
instance_container.setVisibility(View.VISIBLE);
|
|
|
|
loader.setVisibility(View.GONE);
|
2020-08-31 19:00:17 +02:00
|
|
|
});
|
2020-02-20 11:20:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|