Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Feature Request #2985 - custom name editor #3308

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.animation.ArgbEvaluator;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.NotificationManager;
import android.content.ActivityNotFoundException;
Expand Down Expand Up @@ -247,6 +248,7 @@ public class MainActivity extends BaseActivity
private AsyncGetSubreddit mAsyncGetSubreddit = null;
private int headerHeight; //height of the header
public int reloadItemNumber = -2;
TextView nameTextView;

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Expand Down Expand Up @@ -1485,7 +1487,20 @@ public void doDrawer() {
hea = header.findViewById(R.id.back);

drawerSubList.addHeaderView(header, null, false);
((TextView) header.findViewById(R.id.name)).setText(Authentication.name);
nameTextView = ((TextView) header.findViewById(R.id.name));
// Fetching fakename in shared preferences
SharedPreferences sharedPref = MainActivity.this.getSharedPreferences("FAKEUSERNAME", Context.MODE_PRIVATE);
String fakeName = sharedPref.getString("FAKEUSERNAME", "");
if (fakeName.equals("")) {
fakeName = Authentication.name;
}
nameTextView.setText(fakeName);
nameTextView.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
openDialog();
}
});
header.findViewById(R.id.multi).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Expand Down Expand Up @@ -2321,6 +2336,37 @@ public void onSelection(MaterialDialog dialog,
});
}

public void openDialog() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);

View layout = getLayoutInflater().inflate(R.layout.fakename_layout, null);
TextView title = layout.findViewById(R.id.fakename_title);
title.setText("Write your fake username");
EditText edittext = layout.findViewById(R.id.fakename_text);
alertDialog.setView(layout);

alertDialog.setPositiveButton("Save",
(dialog, which) -> {
String fakeName = edittext.getText().toString();

SharedPreferences sharedPref = MainActivity.this.getSharedPreferences("FAKEUSERNAME", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("FAKEUSERNAME", fakeName);
editor.apply();

if (fakeName.equals("")) {
nameTextView.setText(Authentication.name);
} else {
nameTextView.setText(fakeName);
}
});

alertDialog.setNegativeButton("Cancel",
(dialog, which) -> dialog.cancel());

alertDialog.show();
}

public void doPageSelectedComments(int position) {

pager.setSwipeLeftOnly(false);
Expand Down
Loading