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

[Feature Request 2985] Custom username editor #3309

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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,21 @@ public void doDrawer() {
hea = header.findViewById(R.id.back);

drawerSubList.addHeaderView(header, null, false);
((TextView) header.findViewById(R.id.name)).setText(Authentication.name);
nameTextView = 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.isEmpty()) {
fakeName = Authentication.name;
}
nameTextView.setText(fakeName);
nameTextView.setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View v) {
fakenameDialog();
}
});

header.findViewById(R.id.multi).setOnClickListener(new OnSingleClickListener() {
@Override
public void onSingleClick(View view) {
Expand Down Expand Up @@ -2321,6 +2337,37 @@ public void onSelection(MaterialDialog dialog,
});
}

private void fakenameDialog() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);

View layout = getLayoutInflater().inflate(R.layout.fakename_dialog, 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.isEmpty()) {
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
21 changes: 21 additions & 0 deletions app/src/main/res/layout/fakename_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp"
android:orientation="vertical">

<TextView
android:id="@+id/fakename_title"
android:layout_width="match_parent"
android:textColor="#000"
android:layout_height="wrap_content" />

<EditText
android:id="@+id/fakename_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLength="10"
android:textColor="#000" />

</LinearLayout>