diff options
Diffstat (limited to 'src/main/java/de/pixart/messenger/ui')
4 files changed, 269 insertions, 157 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java index c55a936cd..ed2dfee04 100644 --- a/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConferenceDetailsActivity.java @@ -299,7 +299,20 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers this.mAdvancedMode = getPreferences().getBoolean("advanced_muc_mode", false); this.binding.mucInfoMore.setVisibility(this.mAdvancedMode ? View.VISIBLE : View.GONE); this.binding.notificationStatusButton.setOnClickListener(this.mNotifyStatusClickListener); - this.binding.notificationStatusButton.setOnClickListener(this.mNotifyStatusClickListener); + this.binding.detailsMucAvatar.setOnClickListener(v -> { + final MucOptions mucOptions = mConversation.getMucOptions(); + if (!mucOptions.hasVCards()) { + Toast.makeText(this, R.string.host_does_not_support_group_chat_avatars, Toast.LENGTH_SHORT).show(); + return; + } + if (!mucOptions.getSelf().getAffiliation().ranks(MucOptions.Affiliation.OWNER)) { + Toast.makeText(this, R.string.only_the_owner_can_change_group_chat_avatar, Toast.LENGTH_SHORT).show(); + return; + } + final Intent intent = new Intent(this, PublishGroupChatProfilePictureActivity.class); + intent.putExtra("uuid", mConversation.getUuid()); + startActivity(intent); + }); } @Override @@ -320,14 +333,6 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers case android.R.id.home: finish(); break; - case R.id.action_edit_subject: - if (mConversation != null) { - quickEdit(mConversation.getMucOptions().getSubject(), - R.string.edit_subject_hint, - this.onSubjectEdited, - true); - } - break; case R.id.action_share_http: shareLink(true); break; @@ -363,12 +368,10 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers @Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem menuItemAdvancedMode = menu.findItem(R.id.action_advanced_mode); - MenuItem menuItemChangeSubject = menu.findItem(R.id.action_edit_subject); menuItemAdvancedMode.setChecked(mAdvancedMode); if (mConversation == null) { return true; } - menuItemChangeSubject.setVisible(mConversation.getMucOptions().canChangeSubject()); return true; } @@ -587,28 +590,25 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers absubtitle.setClickable(false); } } - this.binding.conferenceName.setText(mConversation.getName()); this.binding.detailsAccount.setText(getString(R.string.using_account, account)); + this.binding.jid.setText(mConversation.getJid().asBareJid().toEscapedString()); if (xmppConnectionService.multipleAccounts()) { this.binding.detailsAccount.setVisibility(View.VISIBLE); } else { this.binding.detailsAccount.setVisibility(View.GONE); } this.binding.yourPhoto.setImageBitmap(avatarService().get(mConversation.getAccount(), getPixel(48))); - setTitle(mConversation.getName()); - this.binding.mucJabberid.setText(mConversation.getJid().asBareJid().toString()); + + this.binding.mucTitle.setText(mucOptions.getName()); + this.binding.mucSubject.setText(mucOptions.getSubject()); this.binding.mucYourNick.setText(mucOptions.getActualNick()); if (mucOptions.online()) { this.binding.mucMoreDetails.setVisibility(View.VISIBLE); this.binding.mucSettings.setVisibility(View.VISIBLE); this.binding.mucInfoMore.setVisibility(this.mAdvancedMode ? View.VISIBLE : View.GONE); - final String status = getStatus(self); - if (status != null) { - this.binding.mucRole.setVisibility(View.VISIBLE); - this.binding.mucRole.setText(status); - } else { - this.binding.mucRole.setVisibility(View.GONE); - } + this.binding.jid.setVisibility(this.mAdvancedMode ? View.VISIBLE : View.GONE); + this.binding.mucRole.setVisibility(View.VISIBLE); + this.binding.mucRole.setText(getStatus(self)); if (mucOptions.membersOnly()) { this.binding.mucConferenceType.setText(R.string.private_conference); } else { @@ -629,7 +629,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers this.binding.changeConferenceButton.setVisibility(View.VISIBLE); } else { this.binding.destroy.setVisibility(View.GONE); - this.binding.changeConferenceButton.setVisibility(View.GONE); + this.binding.changeConferenceButton.setVisibility(View.INVISIBLE); } this.binding.leaveMuc.setVisibility(View.VISIBLE); this.binding.leaveMuc.setOnClickListener(v1 -> { diff --git a/src/main/java/de/pixart/messenger/ui/PublishGroupChatProfilePictureActivity.java b/src/main/java/de/pixart/messenger/ui/PublishGroupChatProfilePictureActivity.java new file mode 100644 index 000000000..a4bf6b440 --- /dev/null +++ b/src/main/java/de/pixart/messenger/ui/PublishGroupChatProfilePictureActivity.java @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2018, Daniel Gultsch All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package de.pixart.messenger.ui; + +import android.content.Intent; +import android.databinding.DataBindingUtil; +import android.graphics.Bitmap; +import android.net.Uri; +import android.os.Bundle; +import android.support.annotation.StringRes; +import android.support.v7.widget.Toolbar; +import android.util.Log; +import android.view.View; +import android.widget.Toast; + +import com.theartofdev.edmodo.cropper.CropImage; + +import de.pixart.messenger.Config; +import de.pixart.messenger.R; +import de.pixart.messenger.databinding.ActivityPublishProfilePictureBinding; +import de.pixart.messenger.entities.Conversation; +import de.pixart.messenger.ui.interfaces.OnAvatarPublication; +import de.pixart.messenger.ui.util.PendingItem; + +public class PublishGroupChatProfilePictureActivity extends XmppActivity implements OnAvatarPublication { + + private static final int REQUEST_CHOOSE_FILE = 0xac24; + + private ActivityPublishProfilePictureBinding binding; + + private final PendingItem<String> pendingConversationUuid = new PendingItem<>(); + + private Conversation conversation; + private Uri uri; + + @Override + protected void refreshUiReal() { + + } + + @Override + void onBackendConnected() { + String uuid = pendingConversationUuid.pop(); + if (uuid != null) { + this.conversation = xmppConnectionService.findConversationByUuid(uuid); + } + if (this.conversation == null) { + return; + } + reloadAvatar(); + } + + private void reloadAvatar() { + final int size = getPixel(Config.AVATAR_SIZE); + Bitmap bitmap; + if (uri == null) { + bitmap = xmppConnectionService.getAvatarService().get(conversation, size); + } else { + Log.d(Config.LOGTAG, "loading " + uri.toString() + " into preview"); + bitmap = xmppConnectionService.getFileBackend().cropCenterSquare(uri, size); + } + this.binding.accountImage.setImageBitmap(bitmap); + this.binding.publishButton.setEnabled(uri != null); + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + this.binding = DataBindingUtil.setContentView(this, R.layout.activity_publish_profile_picture); + setSupportActionBar((Toolbar) this.binding.toolbar); + configureActionBar(getSupportActionBar()); + this.binding.cancelButton.setOnClickListener((v) -> this.finish()); + this.binding.secondaryHint.setVisibility(View.GONE); + this.binding.accountImage.setOnClickListener((v) -> this.chooseAvatar()); + Intent intent = getIntent(); + String uuid = intent == null ? null : intent.getStringExtra("uuid"); + if (uuid != null) { + pendingConversationUuid.push(uuid); + } + this.binding.publishButton.setEnabled(uri != null); + this.binding.publishButton.setOnClickListener(this::publish); + } + + + private void publish(View view) { + xmppConnectionService.publishMucAvatar(conversation, uri, this); + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) { + CropImage.ActivityResult result = CropImage.getActivityResult(data); + if (resultCode == RESULT_OK) { + this.uri = result.getUri(); + if (xmppConnectionServiceBound) { + reloadAvatar(); + } + } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) { + Exception error = result.getError(); + if (error != null) { + Toast.makeText(this, error.getMessage(), Toast.LENGTH_SHORT).show(); + } + } + } + } + + private void chooseAvatar() { + CropImage.activity() + .setOutputCompressFormat(Bitmap.CompressFormat.PNG) + .setAspectRatio(1, 1) + .setMinCropResultSize(Config.AVATAR_SIZE, Config.AVATAR_SIZE) + .start(this); + } + + @Override + public void onAvatarPublicationSucceeded() { + finish(); + } + + @Override + public void onAvatarPublicationFailed(@StringRes int res) { + runOnUiThread(() -> { + Toast.makeText(this,res,Toast.LENGTH_SHORT).show(); + this.binding.publishButton.setText(R.string.publish); + this.binding.publishButton.setEnabled(true); + }); + } +}
\ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/ui/PublishProfilePictureActivity.java b/src/main/java/de/pixart/messenger/ui/PublishProfilePictureActivity.java index 8dfcd11da..a6f158646 100644 --- a/src/main/java/de/pixart/messenger/ui/PublishProfilePictureActivity.java +++ b/src/main/java/de/pixart/messenger/ui/PublishProfilePictureActivity.java @@ -1,16 +1,11 @@ package de.pixart.messenger.ui; -import android.app.PendingIntent; import android.content.Intent; -import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; -import android.support.annotation.NonNull; import android.support.annotation.StringRes; import android.util.Log; -import android.view.Menu; -import android.view.MenuItem; import android.view.View; import android.view.View.OnLongClickListener; import android.widget.Button; @@ -18,25 +13,18 @@ import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; -import com.soundcloud.android.crop.Crop; - -import java.io.File; +import com.theartofdev.edmodo.cropper.CropImage; import de.pixart.messenger.Config; import de.pixart.messenger.R; import de.pixart.messenger.entities.Account; -import de.pixart.messenger.persistance.FileBackend; import de.pixart.messenger.services.XmppConnectionService; -import de.pixart.messenger.utils.FileUtils; +import de.pixart.messenger.ui.interfaces.OnAvatarPublication; import de.pixart.messenger.utils.PhoneHelper; -import de.pixart.messenger.xmpp.pep.Avatar; -public class PublishProfilePictureActivity extends XmppActivity implements XmppConnectionService.OnAccountUpdate { +public class PublishProfilePictureActivity extends XmppActivity implements XmppConnectionService.OnAccountUpdate, OnAvatarPublication { - private static final int REQUEST_CHOOSE_FILE_AND_CROP = 0xac23; - private static final int REQUEST_CHOOSE_FILE = 0xac24; private ImageView avatar; - private TextView accountTextView; private TextView hintOrWarning; private TextView secondaryHint; private Button cancelButton; @@ -56,41 +44,33 @@ public class PublishProfilePictureActivity extends XmppActivity implements XmppC } }; private boolean mInitialAccountSetup; - private UiCallback<Avatar> avatarPublication = new UiCallback<Avatar>() { - - @Override - public void success(Avatar object) { - runOnUiThread(() -> { - if (mInitialAccountSetup) { - Intent intent = new Intent(getApplicationContext(), StartConversationActivity.class); - WelcomeActivity.addInviteUri(intent, getIntent()); - intent.putExtra("init", true); - startActivity(intent); - overridePendingTransition(R.animator.fade_in, R.animator.fade_out); - } - Toast.makeText(PublishProfilePictureActivity.this, - R.string.avatar_has_been_published, - Toast.LENGTH_SHORT).show(); - finish(); - }); - } - - @Override - public void error(final int errorCode, Avatar object) { - runOnUiThread(() -> { - hintOrWarning.setText(errorCode); - hintOrWarning.setTextColor(getWarningTextColor()); - hintOrWarning.setVisibility(View.VISIBLE); - publishing = false; - togglePublishButton(true,R.string.publish); - }); - } + @Override + public void onAvatarPublicationSucceeded() { + runOnUiThread(() -> { + if (mInitialAccountSetup) { + Intent intent = new Intent(getApplicationContext(), StartConversationActivity.class); + WelcomeActivity.addInviteUri(intent, getIntent()); + intent.putExtra("init", true); + startActivity(intent); + } + Toast.makeText(PublishProfilePictureActivity.this, + R.string.avatar_has_been_published, + Toast.LENGTH_SHORT).show(); + finish(); + }); + } - @Override - public void userInputRequried(PendingIntent pi, Avatar object) { - } - }; + @Override + public void onAvatarPublicationFailed(int res) { + runOnUiThread(() -> { + hintOrWarning.setText(res); + hintOrWarning.setTextColor(getWarningTextColor()); + hintOrWarning.setVisibility(View.VISIBLE); + publishing = false; + togglePublishButton(true, R.string.publish); + }); + } @Override public void onCreate(Bundle savedInstanceState) { @@ -98,6 +78,7 @@ public class PublishProfilePictureActivity extends XmppActivity implements XmppC setContentView(R.layout.activity_publish_profile_picture); setSupportActionBar(findViewById(R.id.toolbar)); configureActionBar(getSupportActionBar()); + this.avatar = findViewById(R.id.account_image); this.cancelButton = findViewById(R.id.cancel_button); this.publishButton = findViewById(R.id.publish_button); @@ -106,8 +87,8 @@ public class PublishProfilePictureActivity extends XmppActivity implements XmppC this.publishButton.setOnClickListener(v -> { if (avatarUri != null) { publishing = true; - togglePublishButton(false,R.string.publishing); - xmppConnectionService.publishAvatar(account, avatarUri, avatarPublication); + togglePublishButton(false, R.string.publishing); + xmppConnectionService.publishAvatar(account, avatarUri, this); } }); this.cancelButton.setOnClickListener(v -> { @@ -118,103 +99,38 @@ public class PublishProfilePictureActivity extends XmppActivity implements XmppC intent.putExtra("init", true); } startActivity(intent); - overridePendingTransition(R.animator.fade_in, R.animator.fade_out); } finish(); }); - this.avatar.setOnClickListener(v -> { - if (hasStoragePermission(REQUEST_CHOOSE_FILE)) { - chooseAvatar(false); - } - }); + this.avatar.setOnClickListener(v -> chooseAvatar()); this.defaultUri = PhoneHelper.getProfilePictureUri(getApplicationContext()); } - private void chooseAvatar(boolean crop) { - Intent attachFileIntent = new Intent(); - attachFileIntent.setType("image/*"); - attachFileIntent.setAction(Intent.ACTION_GET_CONTENT); - Intent chooser = Intent.createChooser(attachFileIntent, getString(R.string.attach_file)); - startActivityForResult(chooser, crop ? REQUEST_CHOOSE_FILE_AND_CROP : REQUEST_CHOOSE_FILE); - overridePendingTransition(R.animator.fade_in, R.animator.fade_out); - } @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { - if (grantResults.length > 0) - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { - if (requestCode == REQUEST_CHOOSE_FILE_AND_CROP) { - chooseAvatar(true); - } else if (requestCode == REQUEST_CHOOSE_FILE) { - chooseAvatar(false); + public void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) { + CropImage.ActivityResult result = CropImage.getActivityResult(data); + if (resultCode == RESULT_OK) { + this.avatarUri = result.getUri(); + if (xmppConnectionServiceBound) { + loadImageIntoPreview(this.avatarUri); + } + } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) { + Exception error = result.getError(); + if (error != null) { + Toast.makeText(this, error.getMessage(), Toast.LENGTH_SHORT).show(); } - } else { - Toast.makeText(this, R.string.no_storage_permission, Toast.LENGTH_SHORT).show(); - } - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.publish_avatar, menu); - return super.onCreateOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(final MenuItem item) { - if (item.getItemId() == R.id.action_crop_image) { - if (hasStoragePermission(REQUEST_CHOOSE_FILE_AND_CROP)) { - chooseAvatar(true); } - return true; - } else { - return super.onOptionsItemSelected(item); } } - @Override - protected void onActivityResult(int requestCode, int resultCode, final Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (resultCode == RESULT_OK) { - Uri source = data.getData(); - switch (requestCode) { - case REQUEST_CHOOSE_FILE_AND_CROP: - if (FileBackend.weOwnFile(this, source)) { - Toast.makeText(this, R.string.security_error_invalid_file_access, Toast.LENGTH_SHORT).show(); - return; - } - String original = FileUtils.getPath(this, source); - if (original != null) { - source = Uri.parse("file://" + original); - } - Uri destination = Uri.fromFile(new File(getCacheDir(), "croppedAvatar")); - final int size = getPixel(Config.AVATAR_SIZE); - Crop.of(source, destination).asSquare().withMaxSize(size, size).start(this); - break; - case REQUEST_CHOOSE_FILE: - if (FileBackend.weOwnFile(this, source)) { - Toast.makeText(this, R.string.security_error_invalid_file_access, Toast.LENGTH_SHORT).show(); - return; - } - this.avatarUri = source; - if (xmppConnectionServiceBound) { - loadImageIntoPreview(this.avatarUri); - } - break; - case Crop.REQUEST_CROP: - this.avatarUri = Uri.fromFile(new File(getCacheDir(), "croppedAvatar")); - if (xmppConnectionServiceBound) { - loadImageIntoPreview(this.avatarUri); - } - break; - } - } else { - if (requestCode == Crop.REQUEST_CROP && data != null) { - Throwable throwable = Crop.getError(data); - if (throwable != null && throwable instanceof OutOfMemoryError) { - Toast.makeText(this, R.string.selection_too_large, Toast.LENGTH_SHORT).show(); - } - } - } + private void chooseAvatar() { + CropImage.activity() + .setOutputCompressFormat(Bitmap.CompressFormat.PNG) + .setAspectRatio(1, 1) + .setMinCropResultSize(Config.AVATAR_SIZE, Config.AVATAR_SIZE) + .start(this); } @Override @@ -251,6 +167,7 @@ public class PublishProfilePictureActivity extends XmppActivity implements XmppC } protected void loadImageIntoPreview(Uri uri) { + Bitmap bm = null; if (uri == null) { bm = avatarService().get(account, getPixel(Config.AVATAR_SIZE)); @@ -308,4 +225,5 @@ public class PublishProfilePictureActivity extends XmppActivity implements XmppC public void onAccountUpdate() { refreshUi(); } -} + +}
\ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/ui/interfaces/OnAvatarPublication.java b/src/main/java/de/pixart/messenger/ui/interfaces/OnAvatarPublication.java new file mode 100644 index 000000000..86df8d420 --- /dev/null +++ b/src/main/java/de/pixart/messenger/ui/interfaces/OnAvatarPublication.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2018, Daniel Gultsch All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package de.pixart.messenger.ui.interfaces; + +import android.support.annotation.StringRes; + +public interface OnAvatarPublication { + + void onAvatarPublicationSucceeded(); + + void onAvatarPublicationFailed(@StringRes int res); + +}
\ No newline at end of file |