mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
add status/footer to "your profile" settings #76
This commit is contained in:
+3
-3
@@ -458,15 +458,15 @@
|
||||
<provider android:name=".providers.PartProvider"
|
||||
android:grantUriPermissions="true"
|
||||
android:exported="false"
|
||||
android:authorities="{$applicationId}.provider.securesms" />
|
||||
android:authorities="${applicationId}.provider.securesms" />
|
||||
|
||||
<provider android:name=".providers.MmsBodyProvider"
|
||||
android:grantUriPermissions="true"
|
||||
android:exported="false"
|
||||
android:authorities="{$applicationId}.provider.securesms.mms" />
|
||||
android:authorities="${applicationId}.provider.securesms.mms" />
|
||||
|
||||
<provider android:name="android.support.v4.content.FileProvider"
|
||||
android:authorities="{$applicationId}.fileprovider"
|
||||
android:authorities="${applicationId}.fileprovider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
|
||||
|
||||
@@ -43,6 +43,23 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:id="@+id/status"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<android.support.design.widget.TextInputEditText
|
||||
android:id="@+id/status_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/default_status_hint"
|
||||
android:inputType="text" />
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<LinearLayout android:id="@+id/information_link_container"
|
||||
android:clickable="true"
|
||||
android:orientation="horizontal"
|
||||
|
||||
@@ -1480,5 +1480,6 @@
|
||||
<string name="security_authentication_unlock_description">Please enter your system defined secret to unlock Delta Chat.</string>
|
||||
<!-- Translators: The URL should not be localized, it is not clear which languuage the receiver prefers and the language will be detected on the server -->
|
||||
<string name="default_status_text">Sent with my Delta Chat Messenger: https://delta.chat</string>
|
||||
<string name="default_status_hint">Status text</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -16,6 +16,7 @@ import android.provider.MediaStore;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.support.design.widget.TextInputEditText;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
@@ -95,6 +96,7 @@ public class CreateProfileActivity extends BaseActionBarActivity implements Inje
|
||||
private EditText name;
|
||||
private EmojiToggle emojiToggle;
|
||||
private EmojiDrawer emojiDrawer;
|
||||
private TextInputEditText statusView;
|
||||
private View reveal;
|
||||
|
||||
private Intent nextIntent;
|
||||
@@ -118,6 +120,7 @@ public class CreateProfileActivity extends BaseActionBarActivity implements Inje
|
||||
initializeEmojiInput();
|
||||
initializeProfileName(getIntent().getBooleanExtra(EXCLUDE_SYSTEM, false));
|
||||
initializeProfileAvatar(getIntent().getBooleanExtra(EXCLUDE_SYSTEM, false));
|
||||
initializeStatusText();
|
||||
|
||||
ApplicationContext.getInstance(this).injectDependencies(this);
|
||||
}
|
||||
@@ -229,6 +232,7 @@ public class CreateProfileActivity extends BaseActionBarActivity implements Inje
|
||||
this.container = ViewUtil.findById(this, R.id.container);
|
||||
this.finishButton = ViewUtil.findById(this, R.id.finish_button);
|
||||
this.reveal = ViewUtil.findById(this, R.id.reveal);
|
||||
this.statusView = ViewUtil.findById(this, R.id.status_text);
|
||||
this.nextIntent = getIntent().getParcelableExtra(NEXT_INTENT);
|
||||
|
||||
this.avatar.setImageDrawable(new ResourceContactPhoto(R.drawable.ic_camera_alt_white_24dp).asDrawable(this, getResources().getColor(R.color.grey_400)));
|
||||
@@ -374,6 +378,14 @@ public class CreateProfileActivity extends BaseActionBarActivity implements Inje
|
||||
this.name.setOnClickListener(v -> container.showSoftkey(name));
|
||||
}
|
||||
|
||||
private void initializeStatusText() {
|
||||
String status = DcHelper.get(this, DcHelper.CONFIG_SELF_STATUS);
|
||||
if (status.isEmpty()) {
|
||||
status = getString(R.string.default_status_text);
|
||||
}
|
||||
statusView.setText(status);
|
||||
}
|
||||
|
||||
private Intent createAvatarSelectionIntent(@Nullable File captureFile, boolean includeClear, boolean includeCamera) {
|
||||
List<Intent> extraIntents = new LinkedList<>();
|
||||
Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
|
||||
@@ -440,6 +452,7 @@ public class CreateProfileActivity extends BaseActionBarActivity implements Inje
|
||||
Context context = CreateProfileActivity.this;
|
||||
byte[] profileKey = ProfileKeyUtil.getProfileKey(CreateProfileActivity.this);
|
||||
DcHelper.set(context, DcHelper.CONFIG_DISPLAY_NAME, name);
|
||||
setStatusText();
|
||||
TextSecurePreferences.setProfileName(context, name);
|
||||
|
||||
try {
|
||||
@@ -470,6 +483,16 @@ public class CreateProfileActivity extends BaseActionBarActivity implements Inje
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
private void setStatusText() {
|
||||
String newStatus = statusView.getText().toString().trim();
|
||||
String defaultStatus = getString(R.string.default_status_text);
|
||||
if (newStatus.equals(defaultStatus)) {
|
||||
DcHelper.set(this, DcHelper.CONFIG_SELF_STATUS, null);
|
||||
} else {
|
||||
DcHelper.set(this, DcHelper.CONFIG_SELF_STATUS, newStatus);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleFinishedLegacy() {
|
||||
finishButton.setProgress(0);
|
||||
if (nextIntent != null) startActivity(nextIntent);
|
||||
|
||||
@@ -20,6 +20,7 @@ public class DcHelper {
|
||||
public static final String CONFIG_SERVER_FLAGS = "server_flags";
|
||||
public static final String CONFIG_DISPLAY_NAME = "displayname";
|
||||
public static final String CONFIG_SELF_STATUS = "selfstatus";
|
||||
public static final String CONFIG_SELF_AVATAR = "selfavatar";
|
||||
public static final String CONFIG_E2EE_ENABLED = "e2ee_enabled";
|
||||
|
||||
public static ApplicationDcContext getContext(Context context) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.support.annotation.Nullable;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
|
||||
import java.io.File;
|
||||
@@ -42,11 +43,12 @@ public class AvatarHelper {
|
||||
}
|
||||
|
||||
public static void delete(@NonNull Context context, @NonNull Address address) {
|
||||
delete(getAvatarFile(context, address));
|
||||
delete(context, getAvatarFile(context, address));
|
||||
}
|
||||
|
||||
public static void delete(@NonNull File avatar) {
|
||||
public static void delete(@NonNull Context context, @NonNull File avatar) {
|
||||
avatar.delete();
|
||||
DcHelper.set(context, DcHelper.CONFIG_SELF_AVATAR, null);
|
||||
}
|
||||
|
||||
public static @NonNull File getAvatarFile(@NonNull Context context, @NonNull Address address) {
|
||||
@@ -67,23 +69,25 @@ public class AvatarHelper {
|
||||
delete(context, address);
|
||||
} else {
|
||||
File avatar = getAvatarFile(context, address);
|
||||
writeAvatarFile(avatar, data);
|
||||
writeAvatarFile(context, avatar, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setAvatar(@NonNull Context context, @NonNull String address, @Nullable byte[] data) throws IOException {
|
||||
File avatar = getAvatarFile(context, address);
|
||||
if (data == null) {
|
||||
delete(avatar);
|
||||
delete(context, avatar);
|
||||
} else {
|
||||
writeAvatarFile(avatar, data);
|
||||
writeAvatarFile(context, avatar, data);
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeAvatarFile(@NonNull File avatar, @Nullable byte[] data) throws IOException {
|
||||
private static void writeAvatarFile(@NonNull Context context, @NonNull File avatar, @Nullable byte[] data) throws IOException {
|
||||
FileOutputStream out = new FileOutputStream(avatar);
|
||||
out.write(data);
|
||||
out.close();
|
||||
String path = avatar.getPath();
|
||||
DcHelper.set(context, DcHelper.CONFIG_SELF_AVATAR, path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user