mirror of
https://github.com/FatttSnake/OxygenToolbox.git
synced 2026-04-06 08:21:27 +08:00
Added launch page switch, LibrariesActivity, setting fragment to about fragment action.
This commit is contained in:
@@ -29,17 +29,7 @@ public class App extends Application {
|
||||
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) {
|
||||
ResourceUtil.init(App.this);
|
||||
SharedPreferencesUtils.init(App.this);
|
||||
String locale = SharedPreferencesUtils.getLocale();
|
||||
String language;
|
||||
String country;
|
||||
if (!locale.equals("default")) {
|
||||
language = locale.substring(0, locale.indexOf("_"));
|
||||
country = locale.substring(locale.indexOf("_") + 1);
|
||||
} else {
|
||||
language = ResourceUtil.getSystemLocale().get(0).getLanguage();
|
||||
country = ResourceUtil.getSystemLocale().get(0).getCountry();
|
||||
}
|
||||
setAppLanguage(getApplicationContext(), new Locale(language, country));
|
||||
setAppLanguage(getApplicationContext(), SharedPreferencesUtils.getLanguage());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -100,7 +100,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
public boolean onCreateOptionsMenu(@NonNull Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.main, menu);
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
package com.fatapp.oxygentoolbox.ui.about;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.SearchView;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.app.SearchManager;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.fatapp.oxygentoolbox.R;
|
||||
import com.fatapp.oxygentoolbox.ui.about.util.LibrariesAdapter;
|
||||
import com.fatapp.oxygentoolbox.util.DependenciesJson;
|
||||
import com.fatapp.oxygentoolbox.util.MultiLanguageUtils;
|
||||
import com.fatapp.oxygentoolbox.util.ResourceUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Objects;
|
||||
|
||||
public class LibrariesActivity extends AppCompatActivity {
|
||||
private Toolbar toolbar;
|
||||
private ConstraintLayout librariesPage;
|
||||
private RecyclerView librariesRecyclerView;
|
||||
private SearchView searchView;
|
||||
|
||||
private LibrariesAdapter librariesAdapter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_libraries);
|
||||
|
||||
initView();
|
||||
initLayout();
|
||||
loadLibraries();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
toolbar = findViewById(R.id.toolbar);
|
||||
librariesPage = findViewById(R.id.libraries_page);
|
||||
librariesRecyclerView = findViewById(R.id.libraries_recycler_view);
|
||||
}
|
||||
|
||||
private void initLayout() {
|
||||
librariesPage.setPadding(0, ResourceUtil.getStatusBarHeight(getWindow(), getApplicationContext()), 0, 0);
|
||||
setSupportActionBar(toolbar);
|
||||
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
|
||||
Objects.requireNonNull(getSupportActionBar()).setTitle(R.string.setting_open_source);
|
||||
}
|
||||
|
||||
private void loadLibraries() {
|
||||
StringBuilder dependenciesJson = new StringBuilder();
|
||||
try {
|
||||
InputStream inputStream = ResourceUtil.getResources().openRawResource(R.raw.dependencies);
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
|
||||
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
|
||||
String str;
|
||||
while ((str = bufferedReader.readLine()) != null) {
|
||||
dependenciesJson.append(str);
|
||||
}
|
||||
DependenciesJson dependencies = new Gson().fromJson(dependenciesJson.toString(), new TypeToken<DependenciesJson>() {
|
||||
}.getType());
|
||||
librariesRecyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
|
||||
librariesAdapter = new LibrariesAdapter(this, dependencies);
|
||||
librariesRecyclerView.addItemDecoration(new LibrariesAdapter.LibrariesItemDecoration());
|
||||
librariesRecyclerView.setAdapter(librariesAdapter);
|
||||
} catch (IOException e) {
|
||||
Log.d("TAG", e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
finish();
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(@NonNull Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.seach_view, menu);
|
||||
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
|
||||
searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
|
||||
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
|
||||
searchView.setMaxWidth(Integer.MAX_VALUE);
|
||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
librariesAdapter.getFilter().filter(query);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
librariesAdapter.getFilter().filter(newText);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
// Close search view when back button pressed
|
||||
if (!searchView.isIconified()) {
|
||||
searchView.setIconified(true);
|
||||
return;
|
||||
}
|
||||
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context newBase) {
|
||||
super.attachBaseContext(MultiLanguageUtils.attachBaseContext(newBase));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
MultiLanguageUtils.attachBaseContext(getApplicationContext());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
package com.fatapp.oxygentoolbox.ui.about.util;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Rect;
|
||||
import android.net.Uri;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Filter;
|
||||
import android.widget.Filterable;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.fatapp.oxygentoolbox.R;
|
||||
import com.fatapp.oxygentoolbox.util.DependenciesJson;
|
||||
import com.fatapp.oxygentoolbox.util.LicenseJson;
|
||||
import com.fatapp.oxygentoolbox.util.ResourceUtil;
|
||||
import com.google.android.material.card.MaterialCardView;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
public class LibrariesAdapter extends RecyclerView.Adapter<LibrariesAdapter.ViewHolder> implements Filterable {
|
||||
private final Context context;
|
||||
private final DependenciesJson dependencies;
|
||||
private List<DependenciesJson.LibrariesDTO> librariesFiltered;
|
||||
|
||||
public LibrariesAdapter(Context context, DependenciesJson dependencies) {
|
||||
this.context = context;
|
||||
this.dependencies = dependencies;
|
||||
this.librariesFiltered = dependencies.getLibraries();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_libraries, parent, false);
|
||||
|
||||
return new ViewHolder(inflate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||
DependenciesJson.LibrariesDTO library = librariesFiltered.get(position);
|
||||
holder.getLibraryName().setText(library.getName());
|
||||
holder.getLibraryCreator().setText(library.getDevelopersStr());
|
||||
holder.getLibraryVersion().setText(library.getArtifactVersion());
|
||||
holder.getLibraryDescription().setText(library.getDescription());
|
||||
holder.getLibraryLicense().setText(getLicensesNameStr(library.getLicenses()));
|
||||
|
||||
String url = library.getWebsite() != null && !library.getWebsite().isEmpty() ? library.getWebsite() : library.getScm() != null && library.getScm().getUrl() != null && !library.getScm().getUrl().isEmpty() ? library.getScm().getUrl() : null;
|
||||
if (url != null) {
|
||||
holder.cardView.setOnClickListener(view -> context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))));
|
||||
}
|
||||
|
||||
holder.getLibraryLicense().setOnClickListener(view -> {
|
||||
for (String license : library.getLicenses()) {
|
||||
try {
|
||||
String licenseStr = new JSONObject(dependencies.getLicenses()).getString(license);
|
||||
LicenseJson licenseObject = new Gson().fromJson(licenseStr, new TypeToken<LicenseJson>() {
|
||||
}.getType());
|
||||
new MaterialAlertDialogBuilder(context).setMessage(licenseObject.getContent()).show();
|
||||
} catch (JSONException e) {
|
||||
new MaterialAlertDialogBuilder(context).setMessage(String.format("Could not load license \"%s\"", license)).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return librariesFiltered.size();
|
||||
}
|
||||
|
||||
private String getLicensesNameStr(List<String> licenses) {
|
||||
StringJoiner stringJoiner = new StringJoiner(", ");
|
||||
for (String license : licenses) {
|
||||
try {
|
||||
String licenseStr = new JSONObject(dependencies.getLicenses()).getString(license);
|
||||
LicenseJson licenseObject = new Gson().fromJson(licenseStr, new TypeToken<LicenseJson>() {
|
||||
}.getType());
|
||||
stringJoiner.add(licenseObject.getName());
|
||||
} catch (JSONException e) {
|
||||
stringJoiner.add(license);
|
||||
}
|
||||
}
|
||||
return stringJoiner.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter getFilter() {
|
||||
return new Filter() {
|
||||
@Override
|
||||
protected FilterResults performFiltering(CharSequence charSequence) {
|
||||
List<DependenciesJson.LibrariesDTO> libraries = new ArrayList<>();
|
||||
if (charSequence.toString().isEmpty()) {
|
||||
libraries = dependencies.getLibraries();
|
||||
} else {
|
||||
for (DependenciesJson.LibrariesDTO library : dependencies.getLibraries()) {
|
||||
if (library.getName().toLowerCase().contains(charSequence.toString().toLowerCase())) {
|
||||
libraries.add(library);
|
||||
}
|
||||
}
|
||||
}
|
||||
FilterResults results = new FilterResults();
|
||||
results.count = libraries.size();
|
||||
results.values = libraries;
|
||||
return results;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
@Override
|
||||
protected void publishResults(CharSequence charSequence, FilterResults filterResults) {
|
||||
librariesFiltered = (ArrayList<DependenciesJson.LibrariesDTO>) filterResults.values;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
private final MaterialCardView cardView;
|
||||
private final TextView libraryName;
|
||||
private final TextView libraryCreator;
|
||||
private final TextView libraryVersion;
|
||||
private final TextView libraryDescription;
|
||||
private final TextView libraryLicense;
|
||||
|
||||
public ViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
cardView = (MaterialCardView) itemView;
|
||||
libraryName = itemView.findViewById(R.id.library_name);
|
||||
libraryCreator = itemView.findViewById(R.id.library_creator);
|
||||
libraryVersion = itemView.findViewById(R.id.library_version);
|
||||
libraryDescription = itemView.findViewById(R.id.library_description);
|
||||
libraryLicense = itemView.findViewById(R.id.library_license);
|
||||
}
|
||||
|
||||
public TextView getLibraryName() {
|
||||
return libraryName;
|
||||
}
|
||||
|
||||
public TextView getLibraryCreator() {
|
||||
return libraryCreator;
|
||||
}
|
||||
|
||||
public TextView getLibraryVersion() {
|
||||
return libraryVersion;
|
||||
}
|
||||
|
||||
public TextView getLibraryDescription() {
|
||||
return libraryDescription;
|
||||
}
|
||||
|
||||
public TextView getLibraryLicense() {
|
||||
return libraryLicense;
|
||||
}
|
||||
}
|
||||
|
||||
public static class LibrariesItemDecoration extends RecyclerView.ItemDecoration {
|
||||
@Override
|
||||
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
|
||||
if (parent.getChildLayoutPosition(view) != 0) {
|
||||
outRect.top = -ResourceUtil.dpToPx(10f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import androidx.viewpager2.widget.ViewPager2;
|
||||
import com.fatapp.oxygentoolbox.R;
|
||||
import com.fatapp.oxygentoolbox.ui.home.fav.FavFragment;
|
||||
import com.fatapp.oxygentoolbox.ui.home.tools.ToolsFragment;
|
||||
import com.fatapp.oxygentoolbox.util.SharedPreferencesUtils;
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||
|
||||
public class HomeFragment extends Fragment {
|
||||
@@ -29,7 +30,7 @@ public class HomeFragment extends Fragment {
|
||||
ViewPager2 bottomNavViewPager = root.findViewById(R.id.bottom_nav_view_pager);
|
||||
BottomNavigationView bottomNavigationView = root.findViewById(R.id.bottom_navigation_view);
|
||||
|
||||
bottomNavViewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback(){
|
||||
bottomNavViewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
bottomNavigationView.getMenu().getItem(position).setChecked(true);
|
||||
@@ -43,13 +44,10 @@ public class HomeFragment extends Fragment {
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment createFragment(int position) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
return new ToolsFragment();
|
||||
case 1:
|
||||
return new FavFragment();
|
||||
if (position == 1) {
|
||||
return new FavFragment();
|
||||
}
|
||||
return null;
|
||||
return new ToolsFragment();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -58,6 +56,8 @@ public class HomeFragment extends Fragment {
|
||||
}
|
||||
});
|
||||
|
||||
bottomNavViewPager.setCurrentItem(SharedPreferencesUtils.getLaunchPage() == SharedPreferencesUtils.LaunchPage.tools ? 0 : 1, false);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,32 +1,26 @@
|
||||
package com.fatapp.oxygentoolbox.ui.setting;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.fatapp.oxygentoolbox.MainActivity;
|
||||
import com.fatapp.oxygentoolbox.R;
|
||||
import com.fatapp.oxygentoolbox.util.MultiLanguageUtils;
|
||||
import com.fatapp.oxygentoolbox.ui.about.LibrariesActivity;
|
||||
import com.fatapp.oxygentoolbox.util.ResourceUtil;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class SettingFragment extends PreferenceFragmentCompat {
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {
|
||||
setPreferencesFromResource(R.xml.fragment_setting, rootKey);
|
||||
ListPreference appLanguage = findPreference("app_language");
|
||||
if (appLanguage != null) {
|
||||
appLanguage.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
ListPreference appLanguagePreference = findPreference(ResourceUtil.getString(R.string.setting_language_key));
|
||||
if (appLanguagePreference != null) {
|
||||
appLanguagePreference.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
Intent intent = new Intent(getActivity(), MainActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
requireActivity().startActivity(intent);
|
||||
@@ -34,5 +28,16 @@ public class SettingFragment extends PreferenceFragmentCompat {
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
Preference aboutPreference = findPreference(ResourceUtil.getString(R.string.setting_about_oxygen_toolbox_key));
|
||||
if (aboutPreference != null) {
|
||||
aboutPreference.setOnPreferenceClickListener(preference -> {
|
||||
Intent intent = new Intent(getActivity(), LibrariesActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
// Navigation.findNavController(requireView()).navigate(R.id.action_setting_to_about);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package com.fatapp.oxygentoolbox.util;
|
||||
|
||||
public class Config {
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package com.fatapp.oxygentoolbox.util;
|
||||
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.annotations.JsonAdapter;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
public class DependenciesJson {
|
||||
|
||||
@SerializedName("metadata")
|
||||
private MetadataDTO metadata;
|
||||
@SerializedName("libraries")
|
||||
private List<LibrariesDTO> libraries;
|
||||
@SerializedName("licenses")
|
||||
@JsonAdapter(RawStringJsonAdapter.class)
|
||||
private String licenses;
|
||||
|
||||
public MetadataDTO getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public List<LibrariesDTO> getLibraries() {
|
||||
return libraries;
|
||||
}
|
||||
|
||||
public String getLicenses() {
|
||||
return licenses;
|
||||
}
|
||||
|
||||
public static class MetadataDTO {
|
||||
@SerializedName("generated")
|
||||
private String generated;
|
||||
|
||||
public String getGenerated() {
|
||||
return generated;
|
||||
}
|
||||
}
|
||||
|
||||
public static class LibrariesDTO {
|
||||
@SerializedName("uniqueId")
|
||||
private String uniqueId;
|
||||
@SerializedName("funding")
|
||||
private List<?> funding;
|
||||
@SerializedName("developers")
|
||||
private List<DevelopersDTO> developers;
|
||||
@SerializedName("artifactVersion")
|
||||
private String artifactVersion;
|
||||
@SerializedName("description")
|
||||
private String description;
|
||||
@SerializedName("name")
|
||||
private String name;
|
||||
@SerializedName("licenses")
|
||||
private List<String> licenses;
|
||||
@SerializedName("scm")
|
||||
private ScmDTO scm;
|
||||
@SerializedName("website")
|
||||
private String website;
|
||||
|
||||
public String getUniqueId() {
|
||||
return uniqueId;
|
||||
}
|
||||
|
||||
public List<?> getFunding() {
|
||||
return funding;
|
||||
}
|
||||
|
||||
public List<DevelopersDTO> getDevelopers() {
|
||||
return developers;
|
||||
}
|
||||
|
||||
public String getDevelopersStr() {
|
||||
StringJoiner stringJoiner = new StringJoiner(", ");
|
||||
for (DevelopersDTO developer : getDevelopers()) {
|
||||
stringJoiner.add(developer.getName());
|
||||
}
|
||||
|
||||
return stringJoiner.toString();
|
||||
}
|
||||
|
||||
public String getArtifactVersion() {
|
||||
return artifactVersion;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public List<String> getLicenses() {
|
||||
return licenses;
|
||||
}
|
||||
|
||||
public ScmDTO getScm() {
|
||||
return scm;
|
||||
}
|
||||
|
||||
public String getWebsite() {
|
||||
return website;
|
||||
}
|
||||
|
||||
public static class ScmDTO {
|
||||
@SerializedName("connection")
|
||||
private String connection;
|
||||
@SerializedName("url")
|
||||
private String url;
|
||||
|
||||
public String getConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DevelopersDTO {
|
||||
@SerializedName("organisationUrl")
|
||||
private String organisationUrl;
|
||||
@SerializedName("name")
|
||||
private String name;
|
||||
|
||||
public String getOrganisationUrl() {
|
||||
return organisationUrl;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
public static class RawStringJsonAdapter extends TypeAdapter<String> {
|
||||
|
||||
@Override
|
||||
public void write(JsonWriter out, String value) throws IOException {
|
||||
out.jsonValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String read(JsonReader in) {
|
||||
return JsonParser.parseReader(in).toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.fatapp.oxygentoolbox.util;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class LicenseJson {
|
||||
@SerializedName("content")
|
||||
private String content;
|
||||
@SerializedName("hash")
|
||||
private String hash;
|
||||
@SerializedName("internalHash")
|
||||
private String internalHash;
|
||||
@SerializedName("url")
|
||||
private String url;
|
||||
@SerializedName("spdxId")
|
||||
private String spdxId;
|
||||
@SerializedName("name")
|
||||
private String name;
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public String getHash() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
public String getInternalHash() {
|
||||
return internalHash;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public String getSpdxId() {
|
||||
return spdxId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +1,25 @@
|
||||
package com.fatapp.oxygentoolbox.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.LocaleList;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.appcompat.view.ContextThemeWrapper;
|
||||
import androidx.core.os.ConfigurationCompat;
|
||||
import androidx.core.os.LocaleListCompat;
|
||||
|
||||
import com.fatapp.oxygentoolbox.R;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
public class MultiLanguageUtils {
|
||||
|
||||
public static Context attachBaseContext(Context context) {
|
||||
String locale;
|
||||
if (SharedPreferencesUtils.isNull()) {
|
||||
locale = "default";
|
||||
} else {
|
||||
locale = SharedPreferencesUtils.getLocale();
|
||||
}
|
||||
String language;
|
||||
String country;
|
||||
if (!locale.equals("default")) {
|
||||
language = locale.substring(0, locale.indexOf("_"));
|
||||
country = locale.substring(locale.indexOf("_") + 1);
|
||||
} else {
|
||||
language = ResourceUtil.getSystemLocale().get(0).getLanguage();
|
||||
country = ResourceUtil.getSystemLocale().get(0).getCountry();
|
||||
}
|
||||
Locale locale = SharedPreferencesUtils.getLanguage();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||
return createConfigurationContext(context, language, country);
|
||||
return createConfigurationContext(context, locale.getLanguage(), locale.getCountry());
|
||||
} else {
|
||||
return updateConfiguration(context, language, country);
|
||||
return updateConfiguration(context, locale.getLanguage(), locale.getCountry());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -109,4 +109,12 @@ public final class ResourceUtil {
|
||||
Configuration configuration = Resources.getSystem().getConfiguration();
|
||||
return ConfigurationCompat.getLocales(configuration);
|
||||
}
|
||||
|
||||
public static int dpToPx(float dp) {
|
||||
return (int) (dp * getDisplayMetrics().density + 0.5f);
|
||||
}
|
||||
|
||||
public static float pxToDp(int px) {
|
||||
return px / getDisplayMetrics().density + 0.5f;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,11 @@ import android.content.SharedPreferences;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.fatapp.oxygentoolbox.R;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
public class SharedPreferencesUtils {
|
||||
private static SharedPreferences preferences;
|
||||
|
||||
@@ -12,11 +17,31 @@ public class SharedPreferencesUtils {
|
||||
preferences = PreferenceManager.getDefaultSharedPreferences(app);
|
||||
}
|
||||
|
||||
public static String getLocale() {
|
||||
return preferences.getString("app_language", "default");
|
||||
public static Locale getLanguage() {
|
||||
String languagePreference;
|
||||
String language;
|
||||
String country;
|
||||
if (SharedPreferencesUtils.isNull() ||
|
||||
(languagePreference = preferences.getString(ResourceUtil.getString(R.string.setting_language_key), ResourceUtil.getString(R.string.setting_language_default_value))).equals(ResourceUtil.getString(R.string.setting_language_default_value))) {
|
||||
language = Objects.requireNonNull(ResourceUtil.getSystemLocale().get(0)).getLanguage();
|
||||
country = Objects.requireNonNull(ResourceUtil.getSystemLocale().get(0)).getCountry();
|
||||
} else {
|
||||
language = languagePreference.substring(0, languagePreference.indexOf("_"));
|
||||
country = languagePreference.substring(languagePreference.indexOf("_") + 1);
|
||||
}
|
||||
|
||||
return new Locale(language, country);
|
||||
}
|
||||
|
||||
public static boolean isNull() {
|
||||
return preferences == null;
|
||||
}
|
||||
|
||||
public static LaunchPage getLaunchPage() {
|
||||
return LaunchPage.valueOf(preferences.getString(ResourceUtil.getString(R.string.setting_launch_page_key), ResourceUtil.getString(R.string.setting_launch_page_default_value)));
|
||||
}
|
||||
|
||||
public enum LaunchPage {
|
||||
tools,favourites
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import android.content.Intent;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.fatapp.oxygentoolbox.R;
|
||||
import com.fatapp.oxygentoolbox.tools.TimeScreenActivity;
|
||||
|
||||
public class ToolsLauncher {
|
||||
public static void launch(Context context, String activity) {
|
||||
|
||||
@@ -1,28 +1,25 @@
|
||||
package com.fatapp.oxygentoolbox.util;
|
||||
|
||||
import android.os.Build;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.fatapp.oxygentoolbox.MainActivity;
|
||||
import com.fatapp.oxygentoolbox.ui.home.HomeFragment;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class ToolsList {
|
||||
private static List<Tool> toolList = new ArrayList<>();
|
||||
|
||||
public static void init(InputStream file) throws IOException {
|
||||
int i;
|
||||
String str;
|
||||
StringBuilder jsonStringBuilder = new StringBuilder();
|
||||
|
||||
while ((i = file.read()) != -1) {
|
||||
jsonStringBuilder.append((char) i);
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(file);
|
||||
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
|
||||
while ((str = bufferedReader.readLine()) != null) {
|
||||
jsonStringBuilder.append(str);
|
||||
}
|
||||
file.close();
|
||||
List<ToolsJson> toolsJsonList = new Gson().fromJson(jsonStringBuilder.toString(), new TypeToken<List<ToolsJson>>() {
|
||||
@@ -44,13 +41,7 @@ public class ToolsList {
|
||||
}
|
||||
|
||||
private static String getLocale(Locales strings) {
|
||||
String language;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
language = ResourceUtil.getResources().getConfiguration().getLocales().get(0).getLanguage();
|
||||
} else {
|
||||
language = ResourceUtil.getResources().getConfiguration().locale.getLanguage();
|
||||
}
|
||||
if (language.equals("zh")) {
|
||||
if (SharedPreferencesUtils.getLanguage().getLanguage().equals("zh")) {
|
||||
return strings.getCn();
|
||||
}
|
||||
return strings.getEn();
|
||||
|
||||
Reference in New Issue
Block a user