diff --git a/app/src/main/java/app/fedilab/android/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/BaseMainActivity.java index 91d919c7..dd2097a8 100644 --- a/app/src/main/java/app/fedilab/android/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/BaseMainActivity.java @@ -418,15 +418,13 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt Intent intent = new Intent(BaseMainActivity.this, CacheActivity.class); startActivity(intent); } else if (id == R.id.nav_about_instance) { - Intent intent = new Intent(BaseMainActivity.this, InstanceActivity.class); - startActivity(intent); + (new InstanceActivity()).show(getSupportFragmentManager(), null); } binding.drawerLayout.close(); return false; }); - - headerMainBinding.instanceInfo.setOnClickListener(v -> startActivity(new Intent(BaseMainActivity.this, InstanceHealthActivity.class))); + headerMainBinding.instanceInfo.setOnClickListener(v -> (new InstanceHealthActivity()).show(getSupportFragmentManager(), null)); headerMainBinding.accountProfilePicture.setOnClickListener(v -> { Intent intent = new Intent(BaseMainActivity.this, ProfileActivity.class); Bundle b = new Bundle(); @@ -585,8 +583,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt alert.show(); return true; } else if (itemId == R.id.action_proxy) { - Intent intent = new Intent(BaseMainActivity.this, ProxyActivity.class); - startActivity(intent); + (new ProxyActivity()).show(getSupportFragmentManager(), null); return true; } return true; diff --git a/app/src/main/java/app/fedilab/android/activities/InstanceActivity.java b/app/src/main/java/app/fedilab/android/activities/InstanceActivity.java index 27f13a7a..650d2782 100644 --- a/app/src/main/java/app/fedilab/android/activities/InstanceActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/InstanceActivity.java @@ -15,9 +15,9 @@ package app.fedilab.android.activities; * see . */ +import android.app.Dialog; import android.content.Intent; import android.content.SharedPreferences; -import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -26,18 +26,16 @@ import android.text.SpannableString; import android.text.Spanned; import android.text.style.ForegroundColorSpan; import android.text.style.UnderlineSpan; -import android.view.MenuItem; import android.view.View; -import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.fragment.app.DialogFragment; import androidx.lifecycle.ViewModelProvider; import androidx.preference.PreferenceManager; import com.bumptech.glide.Glide; -import com.bumptech.glide.request.target.CustomTarget; -import com.bumptech.glide.request.transition.Transition; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; import app.fedilab.android.BaseMainActivity; import app.fedilab.android.R; @@ -48,42 +46,38 @@ import app.fedilab.android.helper.ThemeHelper; import app.fedilab.android.viewmodel.mastodon.InstancesVM; -public class InstanceActivity extends BaseAlertDialogActivity { - +public class InstanceActivity extends DialogFragment { ActivityInstanceBinding binding; private boolean applyMaxChar = false; + @NonNull @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { binding = ActivityInstanceBinding.inflate(getLayoutInflater()); - setContentView(binding.getRoot()); + MaterialAlertDialogBuilder materialAlertDialogBuilder = new MaterialAlertDialogBuilder(requireContext()); + materialAlertDialogBuilder.setView(binding.getRoot()); - getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); - if (getSupportActionBar() != null) - getSupportActionBar().hide(); - SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(InstanceActivity.this); + Dialog dialog = materialAlertDialogBuilder.create(); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); final SpannableString contentAbout = new SpannableString(getString(R.string.action_about_instance)); contentAbout.setSpan(new UnderlineSpan(), 0, contentAbout.length(), 0); - contentAbout.setSpan(new ForegroundColorSpan(ThemeHelper.getAttColor(this, R.attr.colorPrimary)), 0, contentAbout.length(), + contentAbout.setSpan(new ForegroundColorSpan(ThemeHelper.getAttColor(requireContext(), R.attr.colorPrimary)), 0, contentAbout.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); - binding.tos.setText(contentAbout); + binding.about.setText(contentAbout); final SpannableString contentPrivacy = new SpannableString(getString(R.string.action_privacy_policy)); contentPrivacy.setSpan(new UnderlineSpan(), 0, contentPrivacy.length(), 0); - contentPrivacy.setSpan(new ForegroundColorSpan(ThemeHelper.getAttColor(this, R.attr.colorPrimary)), 0, contentPrivacy.length(), + contentPrivacy.setSpan(new ForegroundColorSpan(ThemeHelper.getAttColor(requireContext(), R.attr.colorPrimary)), 0, contentPrivacy.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); binding.privacy.setText(contentPrivacy); - binding.tos.setOnClickListener(v -> Helper.openBrowser(InstanceActivity.this, "https://" + MainActivity.currentInstance + "/about")); - binding.privacy.setOnClickListener(v -> Helper.openBrowser(InstanceActivity.this, "https://" + MainActivity.currentInstance + "/privacy-policy")); - binding.close.setOnClickListener( - - view -> { + binding.about.setOnClickListener(v -> Helper.openBrowser(requireActivity(), "https://" + MainActivity.currentInstance + "/about")); + binding.privacy.setOnClickListener(v -> Helper.openBrowser(requireActivity(), "https://" + MainActivity.currentInstance + "/privacy-policy")); + binding.close.setOnClickListener( view -> { if (applyMaxChar) { String max_char = binding.maxChar.getText().toString(); @@ -96,25 +90,18 @@ public class InstanceActivity extends BaseAlertDialogActivity { } } } - finish(); + requireDialog().dismiss(); } ); - if (getSupportActionBar() != null) { - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setDisplayShowHomeEnabled(true); - } - InstancesVM instancesVM = new ViewModelProvider(InstanceActivity.this).get(InstancesVM.class); instancesVM.getInstance(BaseMainActivity.currentInstance).observe(InstanceActivity.this, instanceInfo -> { - binding.instanceContainer.setVisibility(View.VISIBLE); binding.loader.setVisibility(View.GONE); if (instanceInfo == null || instanceInfo.info == null || instanceInfo.info.description == null) { - binding.maxCharContainer.setVisibility(View.VISIBLE); - binding.instanceContainer.setVisibility(View.GONE); - binding.instanceContact.setVisibility(View.GONE); + binding.instanceData.setVisibility(View.GONE); + binding.contact.setVisibility(View.GONE); int val = sharedpreferences.getInt(getString(R.string.SET_MAX_INSTANCE_CHAR) + MainActivity.currentInstance, -1); if (val != -1) { binding.maxChar.setText(String.valueOf(val)); @@ -123,51 +110,48 @@ public class InstanceActivity extends BaseAlertDialogActivity { } else { Instance instance = instanceInfo.info; - binding.instanceTitle.setText(instance.title); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - binding.instanceDescription.setText(Html.fromHtml(instance.description, Html.FROM_HTML_MODE_LEGACY)); - else - binding.instanceDescription.setText(Html.fromHtml(instance.description)); - if (instance.description == null || instance.description.trim().length() == 0) - binding.instanceDescription.setText(getString(R.string.instance_no_description)); - binding.instanceVersion.setText(instance.version); - binding.instanceUri.setText(instance.uri); - if (instance.email == null) { - binding.instanceContact.hide(); - } + Glide.with(InstanceActivity.this) .asDrawable() + .placeholder(R.drawable.default_banner) .load(instance.thumbnail) - .into(new CustomTarget() { - @Override - public void onResourceReady(@NonNull Drawable resource, @Nullable Transition transition) { - binding.background.setAlpha(0.2f); - binding.background.setBackground(resource); - } + .into(binding.backgroundImage); - @Override - public void onLoadCleared(@Nullable Drawable placeholder) { + binding.name.setText(instance.title); - } - }); + if (instance.description == null || instance.description.trim().length() == 0) + binding.description.setText(getString(R.string.instance_no_description)); + else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + binding.description.setText(Html.fromHtml(instance.description, Html.FROM_HTML_MODE_LEGACY)); + else + binding.description.setText(Html.fromHtml(instance.description)); - binding.instanceContact.setOnClickListener(v -> { + binding.version.setText(instance.version); + + binding.uri.setText(instance.uri); + + if (instance.email == null) { + binding.contact.setVisibility(View.GONE); + } else { + binding.contact.setVisibility(View.VISIBLE); + } + + binding.contact.setOnClickListener(v -> { Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", instance.email, null)); emailIntent.putExtra(Intent.EXTRA_SUBJECT, "[Mastodon] - " + instance.uri); startActivity(Intent.createChooser(emailIntent, getString(R.string.send_email))); }); + + binding.instanceData.setVisibility(View.VISIBLE); } }); - } + return dialog; + } @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == android.R.id.home) { - finish(); - return true; - } - return super.onOptionsItemSelected(item); + public void onDestroyView() { + super.onDestroyView(); + binding = null; } - } diff --git a/app/src/main/java/app/fedilab/android/activities/InstanceHealthActivity.java b/app/src/main/java/app/fedilab/android/activities/InstanceHealthActivity.java deleted file mode 100644 index e25e8801..00000000 --- a/app/src/main/java/app/fedilab/android/activities/InstanceHealthActivity.java +++ /dev/null @@ -1,118 +0,0 @@ -package app.fedilab.android.activities; -/* Copyright 2022 Thomas Schneider - * - * This file is a part of Fedilab - * - * 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. - * - * Fedilab 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 Fedilab; if not, - * see . */ - - -import android.content.Intent; -import android.net.Uri; -import android.os.Bundle; -import android.text.SpannableString; -import android.text.style.UnderlineSpan; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; - -import androidx.lifecycle.ViewModelProvider; - -import com.bumptech.glide.Glide; - -import app.fedilab.android.BaseMainActivity; -import app.fedilab.android.R; -import app.fedilab.android.client.entities.app.InstanceSocial; -import app.fedilab.android.databinding.ActivityInstanceSocialBinding; -import app.fedilab.android.helper.Helper; -import app.fedilab.android.helper.ThemeHelper; -import app.fedilab.android.viewmodel.mastodon.InstanceSocialVM; - - -public class InstanceHealthActivity extends BaseAlertDialogActivity { - - private ActivityInstanceSocialBinding binding; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - binding = ActivityInstanceSocialBinding.inflate(getLayoutInflater()); - - setContentView(binding.getRoot()); - getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); - if (getSupportActionBar() != null) - getSupportActionBar().hide(); - - binding.close.setOnClickListener(view -> finish()); - - SpannableString content = new SpannableString(binding.refInstance.getText().toString()); - content.setSpan(new UnderlineSpan(), 0, content.length(), 0); - binding.refInstance.setText(content); - binding.refInstance.setOnClickListener(view -> { - Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://instances.social")); - startActivity(browserIntent); - }); - - checkInstance(); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == android.R.id.home) { - finish(); - return true; - } - return super.onOptionsItemSelected(item); - } - - - private void checkInstance() { - - - InstanceSocialVM instanceSocialVM = new ViewModelProvider(InstanceHealthActivity.this).get(InstanceSocialVM.class); - instanceSocialVM.getInstances(BaseMainActivity.currentInstance.trim()).observe(InstanceHealthActivity.this, instanceSocialList -> { - if (instanceSocialList != null && instanceSocialList.instances.size() > 0) { - InstanceSocial.Instance instanceSocial = instanceSocialList.instances.get(0); - for (InstanceSocial.Instance instance : instanceSocialList.instances) { - if (instance.name.equalsIgnoreCase(BaseMainActivity.currentInstance.trim())) { - instanceSocial = instance; - break; - } - } - if (instanceSocial.thumbnail != null && !instanceSocial.thumbnail.equals("null")) - Glide.with(InstanceHealthActivity.this) - .asBitmap() - .load(instanceSocial.thumbnail) - .into(binding.backGroundImage); - binding.name.setText(instanceSocial.name); - if (instanceSocial.up) { - binding.up.setText(R.string.is_up); - binding.up.setTextColor(ThemeHelper.getAttColor(this, R.attr.colorPrimary)); - } else { - binding.up.setText(R.string.is_down); - binding.up.setTextColor(ThemeHelper.getAttColor(this, R.attr.colorError)); - } - binding.uptime.setText(getString(R.string.instance_health_uptime, (instanceSocial.uptime * 100))); - if (instanceSocial.checked_at != null) - binding.checkedAt.setText(getString(R.string.instance_health_checkedat, Helper.dateToString(instanceSocial.checked_at))); - binding.values.setText(getString(R.string.instance_health_indication, instanceSocial.version, Helper.withSuffix(instanceSocial.active_users), Helper.withSuffix(instanceSocial.statuses))); - binding.instanceContainer.setVisibility(View.VISIBLE); - } else { - binding.instanceContainer.setVisibility(View.VISIBLE); - binding.mainContainer.setVisibility(View.GONE); - binding.noInstance.setVisibility(View.VISIBLE); - } - binding.loader.setVisibility(View.GONE); - }); - } - - -} diff --git a/app/src/main/java/app/fedilab/android/activities/InstanceHealthActivity.kt b/app/src/main/java/app/fedilab/android/activities/InstanceHealthActivity.kt new file mode 100644 index 00000000..7f921564 --- /dev/null +++ b/app/src/main/java/app/fedilab/android/activities/InstanceHealthActivity.kt @@ -0,0 +1,106 @@ +package app.fedilab.android.activities + +import android.app.Dialog +import android.content.Intent +import android.net.Uri +import android.os.Bundle +import android.text.SpannableString +import android.text.style.UnderlineSpan +import android.view.Window +import androidx.core.view.isVisible +import androidx.fragment.app.DialogFragment +import androidx.lifecycle.ViewModelProvider +import app.fedilab.android.BaseMainActivity +import app.fedilab.android.R +import app.fedilab.android.client.entities.app.InstanceSocial +import app.fedilab.android.databinding.ActivityInstanceSocialBinding +import app.fedilab.android.helper.Helper +import app.fedilab.android.helper.ThemeHelper +import app.fedilab.android.viewmodel.mastodon.InstanceSocialVM +import com.bumptech.glide.Glide +import com.google.android.material.dialog.MaterialAlertDialogBuilder + +/* Copyright 2022 Thomas Schneider + * + * This file is a part of Fedilab + * + * 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. + * + * Fedilab 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 Fedilab; if not, + * see . */ +class InstanceHealthActivity : DialogFragment() { + private var _binding: ActivityInstanceSocialBinding? = null + private val binding: ActivityInstanceSocialBinding get() = _binding!! + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + _binding = ActivityInstanceSocialBinding.inflate(layoutInflater) + binding.close.setOnClickListener { dialog?.dismiss() } + val content = SpannableString(binding.refInstance.text.toString()) + content.setSpan(UnderlineSpan(), 0, content.length, 0) + binding.refInstance.text = content + binding.refInstance.setOnClickListener { + startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://instances.social"))) + } + + val materialAlertDialogBuilder = MaterialAlertDialogBuilder(requireContext()) + materialAlertDialogBuilder.setView(binding.root) + + val dialog = materialAlertDialogBuilder.create() + dialog.requestWindowFeature(Window.FEATURE_NO_TITLE) + dialog.setOnShowListener { checkInstance() } + + return dialog + } + + private fun checkInstance() { + val instanceSocialVM = ViewModelProvider(this@InstanceHealthActivity)[InstanceSocialVM::class.java] + instanceSocialVM.getInstances(BaseMainActivity.currentInstance.trim { it <= ' ' }) + .observe(this@InstanceHealthActivity) { instanceSocialList: InstanceSocial? -> + val instance = instanceSocialList?.instances?.firstOrNull { instance -> + instance.name.equals(BaseMainActivity.currentInstance.trim { it <= ' ' }, ignoreCase = true) + } + if (instance != null) { + instance.thumbnail?.takeIf { it != "null" }?.let { thumbnail -> + Glide.with(this@InstanceHealthActivity) + .asBitmap() + .placeholder(R.drawable.default_banner) + .load(thumbnail) + .into(binding.backgroundImage) + } + binding.name.text = instance.name + if (instance.up) { + binding.up.setText(app.fedilab.android.R.string.is_up) + binding.up.setTextColor(ThemeHelper.getAttColor(requireContext(), app.fedilab.android.R.attr.colorPrimary)) + } else { + binding.up.setText(app.fedilab.android.R.string.is_down) + binding.up.setTextColor(ThemeHelper.getAttColor(requireContext(), app.fedilab.android.R.attr.colorError)) + } + binding.uptime.text = getString(app.fedilab.android.R.string.instance_health_uptime, instance.uptime * 100) + if (instance.checked_at != null) + binding.checkedAt.text = + getString(app.fedilab.android.R.string.instance_health_checkedat, Helper.dateToString(instance.checked_at)) + binding.values.text = getString( + app.fedilab.android.R.string.instance_health_indication, + instance.version, + Helper.withSuffix(instance.active_users.toLong()), + Helper.withSuffix(instance.statuses.toLong()) + ) + } else { + binding.instanceData.isVisible = false + binding.noInstance.isVisible = true + } + binding.loader.isVisible = false + } + } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } +} \ No newline at end of file diff --git a/app/src/main/java/app/fedilab/android/activities/InstanceProfileActivity.java b/app/src/main/java/app/fedilab/android/activities/InstanceProfileActivity.java index 327cf968..73847e8c 100644 --- a/app/src/main/java/app/fedilab/android/activities/InstanceProfileActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/InstanceProfileActivity.java @@ -15,72 +15,64 @@ package app.fedilab.android.activities; * see . */ +import android.app.Dialog; import android.os.Bundle; -import android.text.SpannableString; -import android.view.MenuItem; import android.view.View; -import android.view.ViewGroup; -import android.widget.Button; import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.DialogFragment; import androidx.lifecycle.ViewModelProvider; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; + import app.fedilab.android.R; import app.fedilab.android.databinding.ActivityInstanceProfileBinding; import app.fedilab.android.helper.Helper; import app.fedilab.android.viewmodel.mastodon.NodeInfoVM; import es.dmoral.toasty.Toasty; -public class InstanceProfileActivity extends BaseAlertDialogActivity { - +public class InstanceProfileActivity extends DialogFragment { private String instance; private ActivityInstanceProfileBinding binding; + @NonNull @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - + public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { binding = ActivityInstanceProfileBinding.inflate(getLayoutInflater()); - setContentView(binding.getRoot()); - getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); - Bundle b = getIntent().getExtras(); - if (getSupportActionBar() != null) - getSupportActionBar().hide(); + + MaterialAlertDialogBuilder materialAlertDialogBuilder = new MaterialAlertDialogBuilder(requireContext()); + materialAlertDialogBuilder.setView(binding.getRoot()); + + Dialog dialog = materialAlertDialogBuilder.create(); + + Bundle b = getArguments(); if (b != null) instance = b.getString(Helper.ARG_INSTANCE, null); if (instance == null) { - finish(); + requireDialog().dismiss(); } - Button close = findViewById(R.id.close); - close.setOnClickListener(view -> finish()); + + binding.close.setOnClickListener(v -> requireDialog().dismiss()); + NodeInfoVM nodeInfoVM = new ViewModelProvider(InstanceProfileActivity.this).get(NodeInfoVM.class); nodeInfoVM.getNodeInfo(instance).observe(InstanceProfileActivity.this, nodeInfo -> { if (nodeInfo == null) { - Toasty.error(InstanceProfileActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); - finish(); + Toasty.error(requireContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show(); + requireDialog().dismiss(); return; } binding.name.setText(instance); - SpannableString descriptionSpan; binding.userCount.setText(Helper.withSuffix((nodeInfo.usage.users.total))); binding.statusCount.setText(Helper.withSuffix(((nodeInfo.usage.localPosts)))); String softwareStr = nodeInfo.software.name + " - "; binding.software.setText(softwareStr); binding.version.setText(nodeInfo.software.version); - binding.instanceContainer.setVisibility(View.VISIBLE); binding.loader.setVisibility(View.GONE); }); + + return dialog; } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == android.R.id.home) { - finish(); - return true; - } - return super.onOptionsItemSelected(item); - } - - } diff --git a/app/src/main/java/app/fedilab/android/activities/LoginActivity.java b/app/src/main/java/app/fedilab/android/activities/LoginActivity.java index 0262a836..ee7d77df 100644 --- a/app/src/main/java/app/fedilab/android/activities/LoginActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/LoginActivity.java @@ -179,8 +179,7 @@ public class LoginActivity extends BaseActivity { // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_proxy) { - Intent intent = new Intent(LoginActivity.this, ProxyActivity.class); - startActivity(intent); + (new ProxyActivity()).show(getSupportFragmentManager(), null); } else if (id == R.id.action_request_admin) { item.setChecked(!item.isChecked()); requestedAdmin = item.isChecked(); diff --git a/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java b/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java index ce62c671..3011a772 100644 --- a/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ProfileActivity.java @@ -532,12 +532,11 @@ public class ProfileActivity extends BaseActivity { binding.instanceInfo.setVisibility(View.VISIBLE); binding.instanceInfo.setOnClickListener(v -> { - Intent intent = new Intent(ProfileActivity.this, InstanceProfileActivity.class); + InstanceProfileActivity instanceProfileActivity = new InstanceProfileActivity(); Bundle b = new Bundle(); b.putString(Helper.ARG_INSTANCE, finalAccountInstance); - intent.putExtras(b); - startActivity(intent); - + instanceProfileActivity.setArguments(b); + instanceProfileActivity.show(getSupportFragmentManager(), null); }); } }); diff --git a/app/src/main/java/app/fedilab/android/activities/ProxyActivity.java b/app/src/main/java/app/fedilab/android/activities/ProxyActivity.java index 2ffa6120..9c794470 100644 --- a/app/src/main/java/app/fedilab/android/activities/ProxyActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ProxyActivity.java @@ -15,39 +15,45 @@ package app.fedilab.android.activities; * see . */ +import android.app.Dialog; +import android.content.DialogInterface; import android.content.SharedPreferences; import android.os.Bundle; -import android.view.MenuItem; +import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; +import android.view.Window; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.DialogFragment; import androidx.preference.PreferenceManager; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; + import app.fedilab.android.R; import app.fedilab.android.databinding.ActivityProxyBinding; -public class ProxyActivity extends BaseAlertDialogActivity { +public class ProxyActivity extends DialogFragment { private ActivityProxyBinding binding; private int position; + @NonNull @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(ProxyActivity.this); + public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { binding = ActivityProxyBinding.inflate(getLayoutInflater()); - setContentView(binding.getRoot()); - getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); - if (getSupportActionBar() != null) - getSupportActionBar().hide(); + + MaterialAlertDialogBuilder materialAlertDialogBuilder = new MaterialAlertDialogBuilder(requireContext()); + materialAlertDialogBuilder.setView(binding.getRoot()); + + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); //Enable proxy boolean enable_proxy = sharedpreferences.getBoolean(getString(R.string.SET_PROXY_ENABLED), false); binding.enableProxy.setChecked(enable_proxy); - position = 0; + position = sharedpreferences.getInt(getString(R.string.SET_PROXY_TYPE), 0); String hostVal = sharedpreferences.getString(getString(R.string.SET_PROXY_HOST), "127.0.0.1"); int portVal = sharedpreferences.getInt(getString(R.string.SET_PROXY_PORT), 8118); final String login = sharedpreferences.getString(getString(R.string.SET_PROXY_LOGIN), null); @@ -62,22 +68,17 @@ public class ProxyActivity extends BaseAlertDialogActivity { if (pwd != null && binding.proxyPassword.length() > 0) { binding.proxyPassword.setText(pwd); } - ArrayAdapter adapterTrans = ArrayAdapter.createFromResource(ProxyActivity.this, - R.array.proxy_type_choice, android.R.layout.simple_spinner_dropdown_item); - binding.type.setAdapter(adapterTrans); - binding.type.setSelection(sharedpreferences.getInt(getString(R.string.SET_PROXY_TYPE), 0), false); - binding.type.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView parent, View view, int p, long id) { - position = p; - } - - @Override - public void onNothingSelected(AdapterView parent) { - + if (position == 1) binding.protocol.check(R.id.protocol_socks); + binding.protocol.addOnButtonCheckedListener((group, checkedId, isChecked) -> { + if (isChecked) { + if (checkedId == R.id.protocol_http) + position = 0; + else + position = 1; } }); - binding.setProxySave.setOnClickListener(view -> { + + materialAlertDialogBuilder.setPositiveButton(R.string.save, (dialog1, which) -> { String hostVal1 = binding.host.getText().toString().trim(); String portVal1 = binding.port.getText().toString().trim(); String proxy_loginVal = binding.proxyLogin.getText().toString().trim(); @@ -91,18 +92,24 @@ public class ProxyActivity extends BaseAlertDialogActivity { editor.putString(getString(R.string.SET_PROXY_LOGIN), proxy_loginVal); editor.putString(getString(R.string.SET_PROXY_PASSWORD), proxy_passwordVal); editor.apply(); - finish(); }); + materialAlertDialogBuilder.setNeutralButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); + Dialog dialog = materialAlertDialogBuilder.create(); + dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); + + return dialog; + } + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + + return super.onCreateView(inflater, container, savedInstanceState); } @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == android.R.id.home) { - finish(); - return true; - } - return super.onOptionsItemSelected(item); + public void onDestroyView() { + super.onDestroyView(); + binding = null; } - - } diff --git a/app/src/main/java/app/fedilab/android/activities/admin/AdminAccountActivity.java b/app/src/main/java/app/fedilab/android/activities/admin/AdminAccountActivity.java index ac6892db..0b161768 100644 --- a/app/src/main/java/app/fedilab/android/activities/admin/AdminAccountActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/admin/AdminAccountActivity.java @@ -365,12 +365,11 @@ public class AdminAccountActivity extends BaseActivity { binding.instanceInfo.setVisibility(View.VISIBLE); binding.instanceInfo.setOnClickListener(v -> { - Intent intent = new Intent(AdminAccountActivity.this, InstanceProfileActivity.class); + InstanceProfileActivity instanceProfileActivity = new InstanceProfileActivity(); Bundle b = new Bundle(); b.putString(Helper.ARG_INSTANCE, finalAccountInstance); - intent.putExtras(b); - startActivity(intent); - + instanceProfileActivity.setArguments(b); + instanceProfileActivity.show(getSupportFragmentManager(), null); }); } }); diff --git a/app/src/main/java/app/fedilab/android/activities/admin/AdminReportActivity.java b/app/src/main/java/app/fedilab/android/activities/admin/AdminReportActivity.java index 1d6667dc..35a85d1c 100644 --- a/app/src/main/java/app/fedilab/android/activities/admin/AdminReportActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/admin/AdminReportActivity.java @@ -383,12 +383,11 @@ public class AdminReportActivity extends BaseBarActivity { binding.instanceInfo.setVisibility(View.VISIBLE); binding.instanceInfo.setOnClickListener(v -> { - Intent intent = new Intent(AdminReportActivity.this, InstanceProfileActivity.class); + InstanceProfileActivity instanceProfileActivity = new InstanceProfileActivity(); Bundle b = new Bundle(); b.putString(Helper.ARG_INSTANCE, finalAccountInstance); - intent.putExtras(b); - startActivity(intent); - + instanceProfileActivity.setArguments(b); + instanceProfileActivity.show(getSupportFragmentManager(), null); }); } }); diff --git a/app/src/main/res/layout/activity_instance.xml b/app/src/main/res/layout/activity_instance.xml index 62002d4f..b2f9cac4 100644 --- a/app/src/main/res/layout/activity_instance.xml +++ b/app/src/main/res/layout/activity_instance.xml @@ -14,173 +14,172 @@ You should have received a copy of the GNU General Public License along with Fedilab; if not, see . --> - + android:layout_height="wrap_content" + android:orientation="vertical"> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_gravity="center_horizontal" + android:layout_marginTop="24dp" + android:layout_marginBottom="12dp" + android:text="@string/close" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_instance_profile.xml b/app/src/main/res/layout/activity_instance_profile.xml index 306150fb..519fdd6f 100644 --- a/app/src/main/res/layout/activity_instance_profile.xml +++ b/app/src/main/res/layout/activity_instance_profile.xml @@ -1,198 +1,111 @@ - - - + android:layout_height="wrap_content" + android:orientation="vertical"> + android:layout_height="0dp" + android:layout_weight="1"> - + android:layout_height="wrap_content"> - - - - - - - - - - - - - - - - - - - - - - - - - + android:layout_centerInParent="true" + android:orientation="vertical" + android:padding="12dp"> - + + + + + + + + + + + + + + + + + android:layout_centerInParent="true" + android:indeterminate="true" + android:indeterminateOnly="true" /> - - + - + android:layout_gravity="center_horizontal" + android:layout_marginTop="24dp" + android:layout_marginBottom="12dp" + android:text="@string/close" /> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_instance_social.xml b/app/src/main/res/layout/activity_instance_social.xml index 67b1c622..20422590 100644 --- a/app/src/main/res/layout/activity_instance_social.xml +++ b/app/src/main/res/layout/activity_instance_social.xml @@ -1,130 +1,112 @@ - + android:layout_width="match_parent" + android:layout_height="wrap_content"> - + android:layout_height="0dp" + android:alpha="0.2" + android:contentDescription="@string/logo_of_the_instance" + android:scaleType="centerCrop" + app:layout_constraintDimensionRatio="1:1" + app:layout_constraintTop_toTopOf="parent" + tools:src="@tools:sample/backgrounds/scenic" /> - - - - + android:textAlignment="center" + android:textAppearance="@style/TextAppearance.Material3.TitleLarge" + tools:text="instance.test" /> - - - - - - - - - - - - - - - - - - - - - - - - + android:layout_height="wrap_content" + android:textAlignment="center" + android:textAppearance="@style/TextAppearance.Material3.LabelMedium" + tools:text="version: 4.0\n100 users - 10 k statuses" /> - - + + - \ No newline at end of file + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_proxy.xml b/app/src/main/res/layout/activity_proxy.xml index 2913859b..11a77200 100644 --- a/app/src/main/res/layout/activity_proxy.xml +++ b/app/src/main/res/layout/activity_proxy.xml @@ -1,107 +1,118 @@ + android:padding="12dp"> - + android:text="@string/proxy_enable" /> - + + + + + android:text="@string/proxy_protocol_http" /> - - + android:layout_weight="1" + android:text="@string/proxy_protocol_socks" /> - + + + android:layout_marginTop="12dp"> - + android:dropDownAnchor="@id/login_instance_layout" + android:hint="@string/poxy_host" + android:imeOptions="actionNext" + android:inputType="textUri" + android:singleLine="true" /> - - + - + + - - - - + android:dropDownAnchor="@id/login_instance_layout" + android:hint="@string/poxy_port" + android:imeOptions="actionNext" + android:inputType="number" + android:singleLine="true" /> + + android:layout_marginTop="12dp"> - + + android:layout_height="wrap_content" + android:layout_marginTop="12dp"> + - - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c13598d0..db5251df 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -275,6 +275,9 @@ Proxy Enable proxy? + Protocol + HTTP + SOCKS Host Port Login @@ -311,10 +314,6 @@ Update filter You have not created a list yet. Tap on the \"+\" button to add a new one. Automatically expand hidden media - - HTTP - SOCKS - New follow New Boost New Favourite