Skip to content

Commit

Permalink
Resizing ongoingcall screen and permission utils cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
roeiedri committed Oct 4, 2020
1 parent df98a13 commit f839e42
Show file tree
Hide file tree
Showing 22 changed files with 150 additions and 144 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "com.chooloo.www.callmanager"
minSdkVersion 24
targetSdkVersion 29
versionCode 44
versionName "v0.6.0"
versionCode 45
versionName "v0.6.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

javaCompileOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import com.chooloo.www.callmanager.listener.OnItemLongClickListener;
import com.chooloo.www.callmanager.database.entity.RecentCall;
import com.chooloo.www.callmanager.ui.ListItemHolder;
import com.chooloo.www.callmanager.util.PhoneNumberUtils;
import com.chooloo.www.callmanager.util.RelativeTime;
import com.google.i18n.phonenumbers.PhoneNumberUtil;

import java.util.Date;
import java.util.Dictionary;
Expand Down Expand Up @@ -64,6 +66,7 @@ public void onBindViewHolder(ListItemHolder holder, Cursor cursor) {
Date date = recentCall.getCallDate();

if (callerName == null) callerName = phoneNumber;
// callerName = PhoneNumberUtils.formatPhoneNumber(mContext, phoneNumber);

// hide header
holder.header.setVisibility(View.GONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Phone;

import com.chooloo.www.callmanager.util.Utilities;
import com.chooloo.www.callmanager.util.PermissionUtils;

import java.util.ArrayList;
import java.util.List;

import timber.log.Timber;

import static android.Manifest.permission.READ_CONTACTS;
import static com.chooloo.www.callmanager.util.PermissionUtils.checkPermissionGranted;

/**
* Extends the basic ContactsCursorLoader but also adds the favourite contacts to it
Expand Down Expand Up @@ -92,7 +91,7 @@ private Cursor loadContacts() {
* @return The cursor containing the favorites
*/
private Cursor loadFavorites() {
checkPermissionGranted(getContext(), READ_CONTACTS, true);
PermissionUtils.checkPermissionsGranted(getContext(), new String[]{READ_CONTACTS}, true);
String selection = ContactsCursorLoader.COLUMN_STARRED + " = 1";
return getContext().getContentResolver().query(
buildFavoritesUri(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void actionFav(ImageView view) {
ContactUtils.setContactIsFavorite(this, Long.toString(mContact.getContactId()), true);
}
} else {
PermissionUtils.askForPermission(this, WRITE_CONTACTS);
PermissionUtils.askForPermissions(this, new String[]{WRITE_CONTACTS});
Toast.makeText(this, "I dont have the permission to do that :(", Toast.LENGTH_LONG).show();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import android.os.Handler;
import android.os.Message;
import android.os.PowerManager;
import android.provider.ContactsContract;
import android.telecom.Call;
import android.view.KeyEvent;
import android.view.View;
Expand All @@ -25,6 +24,7 @@
import android.view.WindowManager;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
Expand Down Expand Up @@ -61,8 +61,6 @@
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.textfield.TextInputEditText;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.google.i18n.phonenumbers.Phonenumber;

import org.jetbrains.annotations.NotNull;

Expand All @@ -73,7 +71,11 @@
import butterknife.OnClick;
import timber.log.Timber;

import static android.Manifest.permission.SEND_SMS;
import static android.app.Notification.EXTRA_NOTIFICATION_ID;
import static android.view.View.GONE;
import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;
import static com.chooloo.www.callmanager.util.BiometricUtils.showBiometricPrompt;

@SuppressLint("ClickableViewAccessibility")
Expand Down Expand Up @@ -151,6 +153,7 @@ public class OngoingCallActivity extends AbsThemeActivity implements DialpadFrag
@BindView(R.id.reject_btn) FloatingActionButton mRejectButton;

// Image Views
@BindView(R.id.caller_image_layout) FrameLayout mImageLayout;
@BindView(R.id.image_placeholder) ImageView mPlaceholderImage;
@BindView(R.id.image_photo) ImageView mPhotoImage;
@BindView(R.id.button_hold) ImageView mHoldButton;
Expand Down Expand Up @@ -461,9 +464,9 @@ public void cancelTimer(View view) {
*/
@OnClick(R.id.button_floating_send_sms)
public void setSmsOverlay(View view) {
if (PermissionUtils.checkPermissionGranted(this, Manifest.permission.SEND_SMS, true)) {
if (PermissionUtils.checkPermissionsGranted(this, new String[]{SEND_SMS}, true)) {
setOverlay(mSendSmsOverlay);
mSendSmsButton.setVisibility(View.VISIBLE);
mSendSmsButton.setVisibility(VISIBLE);
mSendSmsOverlay.setOnTouchListener(mSmsOverlaySwipeListener);
}
}
Expand Down Expand Up @@ -542,18 +545,22 @@ private void endCall() {
* Display the information about the caller
*/
private void displayInformation() {
// get caller contact
Contact callerContact = CallManager.getDisplayContact(this);

// set callerName
String callerName = callerContact.getName();
if (callerName == null) {
Timber.i("SETTING CALLER NAME " + callerName);
if (callerName == null)
callerName = PhoneNumberUtils.formatPhoneNumber(this, callerContact.getMainPhoneNumber());
}

// apply details to layout
mCallerText.setText(callerName);
if (callerContact.getPhotoUri() != null) {
mPlaceholderImage.setVisibility(View.INVISIBLE);
mPhotoImage.setVisibility(View.VISIBLE);
mPlaceholderImage.setVisibility(INVISIBLE);
mPhotoImage.setVisibility(VISIBLE);
mPhotoImage.setImageURI(Uri.parse(callerContact.getPhotoUri()));
} else {
mImageLayout.setVisibility(GONE);
}
}

Expand Down Expand Up @@ -623,11 +630,11 @@ private void switchToCallingUI() {

// Change the buttons layout
mAnswerButton.hide();
mHoldButton.setVisibility(View.VISIBLE);
mMuteButton.setVisibility(View.VISIBLE);
mKeypadButton.setVisibility(View.VISIBLE);
mSpeakerButton.setVisibility(View.VISIBLE);
// mAddCallButton.setVisibility(View.VISIBLE);
mHoldButton.setVisibility(VISIBLE);
mMuteButton.setVisibility(VISIBLE);
mKeypadButton.setVisibility(VISIBLE);
mSpeakerButton.setVisibility(VISIBLE);
// mAddCallButton.setVisibility(VISIBLE);
moveRejectButtonToMiddle();
}

Expand Down Expand Up @@ -690,7 +697,7 @@ private void hideButtons() {
assert mFloatingCancelSMS != null;
mFloatingCancelSMS.hide();
mFloatingCancelTimerButton.hide();
mSendSmsButton.setVisibility(View.GONE);
mSendSmsButton.setVisibility(GONE);
}

/**
Expand All @@ -713,15 +720,15 @@ private void setLayerEnabled(@NotNull ViewGroup layer, boolean isEnabled) {
if (v instanceof FloatingActionButton) {
((FloatingActionButton) v).show();
} else {
v.setVisibility(View.VISIBLE);
v.setVisibility(VISIBLE);
}
} else { // If we don't
if (v instanceof FloatingActionButton) { // Make it non-clickable
((FloatingActionButton) v).hide();
} else if (v instanceof Button) {
v.setVisibility(View.GONE);
v.setVisibility(GONE);
} else { // Don't move any other views that are constrained to it
v.setVisibility(View.INVISIBLE);
v.setVisibility(INVISIBLE);
}
v.setHovered(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public void onEditNameIndex(Editable editable) {
* Shows a file chooser for the excel file
*/
private void showFileChooser() {
PermissionUtils.checkPermissionGranted(getActivity(), READ_EXTERNAL_STORAGE, true);
PermissionUtils.checkPermissionsGranted(getActivity(), new String[]{READ_EXTERNAL_STORAGE}, true);
new FileChooserDialog.Builder(getFragmentManager())
.onFileSelected(this)
.extensionsFilter(".xls")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private void showRecentPopup(RecentCall recentCall) {
contactDialog.dismiss();
} else {
Toast.makeText(mContext, "I dont have the permission", Toast.LENGTH_LONG).show();
PermissionUtils.askForPermission(getActivity(), WRITE_CALL_LOG);
PermissionUtils.askForPermissions(getActivity(), new String[]{WRITE_CALL_LOG});
contactDialog.dismiss();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
ListPreference simSelectionPreference = (ListPreference) findPreference(getString(R.string.pref_sim_select_key));
simSelectionPreference.setOnPreferenceChangeListener(listChangeListener);

PermissionUtils.checkPermissionGranted(getContext(), READ_PHONE_STATE, true);
PermissionUtils.checkPermissionsGranted(getContext(), new String[]{READ_PHONE_STATE}, true);
setupSimSelection();
}

Expand All @@ -124,7 +124,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
}

private void setupSimSelection() {
if (!PermissionUtils.checkPermissionGranted(getContext(), READ_PHONE_STATE, true)) {
if (!PermissionUtils.checkPermissionsGranted(getContext(), new String[]{READ_PHONE_STATE}, true)) {
Toast.makeText(getContext(), "No permission, please give permission to read phone state", Toast.LENGTH_LONG).show();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProviders;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.Loader;
import androidx.recyclerview.widget.LinearLayoutManager;
Expand All @@ -22,11 +21,6 @@
import com.chooloo.www.callmanager.adapter.AbsFastScrollerAdapter;
import com.chooloo.www.callmanager.ui.FastScroller;
import com.chooloo.www.callmanager.util.PermissionUtils;
import com.chooloo.www.callmanager.util.Utilities;
import com.chooloo.www.callmanager.viewmodel.SharedDialViewModel;
import com.chooloo.www.callmanager.viewmodel.SharedSearchViewModel;

import java.util.Optional;

import butterknife.BindView;
import butterknife.OnClick;
Expand Down Expand Up @@ -110,10 +104,7 @@ public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State
mRecyclerView.setLayoutManager(mLayoutManager);

// refresh layout
mRefreshLayout.setOnRefreshListener(() -> {
LoaderManager.getInstance(AbsCursorFragment.this).restartLoader(LOADER_ID, null, AbsCursorFragment.this);
load();
});
mRefreshLayout.setOnRefreshListener(this::load);

togglePermissionButton();
load(mPhoneNumber, mContactName);
Expand Down Expand Up @@ -157,7 +148,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c

@OnClick(R.id.enable_permission_btn)
public void enablePermissionClick() {
requestPermissions(mRequiredPermissions, 1);
PermissionUtils.askForPermissions(this, mRequiredPermissions);
}

// -- Loader -- //
Expand All @@ -169,9 +160,8 @@ public void enablePermissionClick() {
* @param contactName name filter
*/
public void load(@Nullable String phoneNumber, @Nullable String contactName) {
if (PermissionUtils.checkPermissionsGranted(mContext, mRequiredPermissions, false)) {
if (PermissionUtils.checkPermissionsGranted(mContext, mRequiredPermissions, false))
runLoader(phoneNumber, contactName);
}
}

public void load() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static void call(@NotNull Activity activity, @NotNull String number) {
int simCard = getSimSelection(activity);

// create call intent
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel: " + Uri.encode(Utilities.getOnlyNumbers(number))));
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel: " + Uri.encode(number)));

// add sim selection to call intent
if (phoneAccountHandleList != null && !phoneAccountHandleList.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static android.Manifest.permission.READ_CONTACTS;
import static android.Manifest.permission.WRITE_CONTACTS;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static com.chooloo.www.callmanager.util.PermissionUtils.checkPermissionsGranted;

public class ContactUtils {

Expand All @@ -41,7 +42,7 @@ public static Contact getContact(@NonNull Context context, String phoneNumber, S
// if phone number is empty, it's a private number
if (phoneNumber.isEmpty() && (name == null || name.isEmpty())) return PRIVATE;
// check for read contacts permission, ask for it if necessary
if (!PermissionUtils.checkPermissionGranted(context, READ_CONTACTS, true)) return UNKNOWN;
if (!checkPermissionsGranted(context, new String[]{READ_CONTACTS}, true)) return UNKNOWN;
// initiate contact cursor
Cursor cursor = new ContactsCursorLoader(context, phoneNumber, name).loadInBackground();
// handle null cursor
Expand Down Expand Up @@ -137,7 +138,7 @@ public static void deleteContact(Activity activity, long contactId) {
public static void setContactIsFavorite(Activity activity, String contactId, boolean isSetFavorite) {
try {
int num = isSetFavorite ? 1 : 0; // convert boolean to num
if (PermissionUtils.checkPermissionGranted(activity, WRITE_CONTACTS, true)) {
if (PermissionUtils.checkPermissionsGranted(activity, new String[]{WRITE_CONTACTS}, true)) {
ContentValues v = new ContentValues();
v.put(ContactsContract.Contacts.STARRED, num);
activity.getContentResolver().update(ContactsContract.Contacts.CONTENT_URI, v, ContactsContract.Contacts._ID + "=?", new String[]{contactId + ""});
Expand Down
Loading

0 comments on commit f839e42

Please sign in to comment.