Skip to content

Commit

Permalink
code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
woheller69 committed Sep 2, 2023
1 parent b9ef250 commit 50b418b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.woheller69.spritpreise.activities;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import androidx.appcompat.app.AlertDialog;
Expand All @@ -10,10 +9,8 @@
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.ItemTouchHelper;

import androidx.preference.PreferenceManager;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.Toast;

Expand Down Expand Up @@ -109,8 +106,6 @@ public void onLongItemClick(View view, int position) {

FloatingActionButton addFab1 = (FloatingActionButton) findViewById(R.id.fabAddLocation);

SharedPreferences prefManager = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

if (addFab1 != null) {

addFab1.setOnClickListener(new View.OnClickListener() {
Expand All @@ -120,7 +115,6 @@ public void onClick(View view) {
AddLocationDialogOmGeocodingAPI addLocationDialog = new AddLocationDialogOmGeocodingAPI();
addLocationDialog.show(fragmentManager, "AddLocationDialog");
getSupportFragmentManager().executePendingTransactions();
addLocationDialog.getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class AddLocationDialogOmGeocodingAPI extends DialogFragment {
private Handler handler;
private AutoSuggestAdapter autoSuggestAdapter;
String url="https://geocoding-api.open-meteo.com/v1/search?name=";
String lang="default";
String lang="de";

@Override
public void onAttach(@NonNull Context context) {
Expand All @@ -79,18 +79,18 @@ public void onAttach(@NonNull Context context) {
public Dialog onCreateDialog(Bundle savedInstanceState) {

Locale locale = ConfigurationCompat.getLocales(Resources.getSystem().getConfiguration()).get(0);
lang=locale.getLanguage();
if (locale != null) lang=locale.getLanguage();

LayoutInflater inflater = getActivity().getLayoutInflater();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = activity.getLayoutInflater();
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
View view = inflater.inflate(R.layout.dialog_add_location, null);

rootView = view;

builder.setView(view);
builder.setTitle(getActivity().getString(R.string.dialog_add_label));
builder.setTitle(activity.getString(R.string.dialog_add_label));

this.database = SQLiteHelper.getInstance(getActivity());
this.database = SQLiteHelper.getInstance(activity);


final WebView webview= rootView.findViewById(R.id.webViewAddLocation);
Expand All @@ -115,7 +115,7 @@ public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
selectedCity=autoSuggestAdapter.getObject(position);
//Hide keyboard to have more space
final InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
final InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(rootView.getWindowToken(), 0);
//Show city on map
webview.loadUrl("file:///android_asset/map.html?lat=" + selectedCity.getLatitude() + "&lon=" + selectedCity.getLongitude());
Expand Down Expand Up @@ -159,15 +159,15 @@ public boolean handleMessage(Message msg) {
}
});

builder.setPositiveButton(getActivity().getString(R.string.dialog_add_add_button), new DialogInterface.OnClickListener() {
builder.setPositiveButton(activity.getString(R.string.dialog_add_add_button), new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
performDone();
}
});

builder.setNegativeButton(getActivity().getString(R.string.dialog_add_close_button), null);
builder.setNegativeButton(activity.getString(R.string.dialog_add_close_button), null);

return builder.create();

Expand Down

0 comments on commit 50b418b

Please sign in to comment.