Code cleaning + fixed contacts list empty if permission given in the fragment after being denied or reset
This commit is contained in:
parent
38908a6581
commit
d092fbbf0f
3 changed files with 34 additions and 45 deletions
|
@ -363,10 +363,6 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeCurrentFragment(FragmentsAvailable newFragmentType, Bundle extras) {
|
private void changeCurrentFragment(FragmentsAvailable newFragmentType, Bundle extras) {
|
||||||
changeCurrentFragment(newFragmentType, extras, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void changeCurrentFragment(FragmentsAvailable newFragmentType, Bundle extras, boolean withoutAnimation) {
|
|
||||||
if (newFragmentType == currentFragment && newFragmentType != FragmentsAvailable.CHAT
|
if (newFragmentType == currentFragment && newFragmentType != FragmentsAvailable.CHAT
|
||||||
&& newFragmentType != FragmentsAvailable.GROUP_CHAT) {
|
&& newFragmentType != FragmentsAvailable.GROUP_CHAT) {
|
||||||
return;
|
return;
|
||||||
|
@ -440,7 +436,7 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
if (fragment != null) {
|
if (fragment != null) {
|
||||||
fragment.setArguments(extras);
|
fragment.setArguments(extras);
|
||||||
if (isTablet()) {
|
if (isTablet()) {
|
||||||
changeFragmentForTablets(fragment, newFragmentType, withoutAnimation);
|
changeFragmentForTablets(fragment, newFragmentType);
|
||||||
switch (newFragmentType) {
|
switch (newFragmentType) {
|
||||||
case HISTORY_LIST:
|
case HISTORY_LIST:
|
||||||
((HistoryListFragment) fragment).displayFirstLog();
|
((HistoryListFragment) fragment).displayFirstLog();
|
||||||
|
@ -453,30 +449,16 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
changeFragment(fragment, newFragmentType, withoutAnimation);
|
changeFragment(fragment, newFragmentType);
|
||||||
}
|
}
|
||||||
LinphoneUtils.hideKeyboard(this);
|
LinphoneUtils.hideKeyboard(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeFragment(Fragment newFragment, FragmentsAvailable newFragmentType, boolean withoutAnimation) {
|
private void changeFragment(Fragment newFragment, FragmentsAvailable newFragmentType) {
|
||||||
FragmentManager fm = getFragmentManager();
|
FragmentManager fm = getFragmentManager();
|
||||||
FragmentTransaction transaction = fm.beginTransaction();
|
FragmentTransaction transaction = fm.beginTransaction();
|
||||||
|
|
||||||
/*if (!withoutAnimation && !isAnimationDisabled && currentFragment.shouldAnimate()) {
|
|
||||||
if (newFragmentType.isRightOf(currentFragment)) {
|
|
||||||
transaction.setCustomAnimations(R.anim.slide_in_right_to_left,
|
|
||||||
R.anim.slide_out_right_to_left,
|
|
||||||
R.anim.slide_in_left_to_right,
|
|
||||||
R.anim.slide_out_left_to_right);
|
|
||||||
} else {
|
|
||||||
transaction.setCustomAnimations(R.anim.slide_in_left_to_right,
|
|
||||||
R.anim.slide_out_left_to_right,
|
|
||||||
R.anim.slide_in_right_to_left,
|
|
||||||
R.anim.slide_out_right_to_left);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (newFragmentType != FragmentsAvailable.DIALER
|
if (newFragmentType != FragmentsAvailable.DIALER
|
||||||
&& newFragmentType != FragmentsAvailable.CONTACTS_LIST
|
&& newFragmentType != FragmentsAvailable.CONTACTS_LIST
|
||||||
&& newFragmentType != FragmentsAvailable.CHAT_LIST
|
&& newFragmentType != FragmentsAvailable.CHAT_LIST
|
||||||
|
@ -496,7 +478,7 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
currentFragment = newFragmentType;
|
currentFragment = newFragmentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeFragmentForTablets(Fragment newFragment, FragmentsAvailable newFragmentType, boolean withoutAnimation) {
|
private void changeFragmentForTablets(Fragment newFragment, FragmentsAvailable newFragmentType) {
|
||||||
if (getResources().getBoolean(R.bool.show_statusbar_only_on_dialer)) {
|
if (getResources().getBoolean(R.bool.show_statusbar_only_on_dialer)) {
|
||||||
if (newFragmentType == FragmentsAvailable.DIALER) {
|
if (newFragmentType == FragmentsAvailable.DIALER) {
|
||||||
showStatusBar();
|
showStatusBar();
|
||||||
|
@ -505,7 +487,7 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
emptyFragment = false;
|
emptyFragment = false;
|
||||||
LinearLayout ll = (LinearLayout) findViewById(R.id.fragmentContainer2);
|
LinearLayout ll = findViewById(R.id.fragmentContainer2);
|
||||||
|
|
||||||
FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
||||||
|
|
||||||
|
@ -1138,7 +1120,7 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
protected void onPostResume() {
|
protected void onPostResume() {
|
||||||
super.onPostResume();
|
super.onPostResume();
|
||||||
if (pendingFragmentTransaction != FragmentsAvailable.UNKNOW) {
|
if (pendingFragmentTransaction != FragmentsAvailable.UNKNOW) {
|
||||||
changeCurrentFragment(pendingFragmentTransaction, null, true);
|
changeCurrentFragment(pendingFragmentTransaction, null);
|
||||||
selectMenu(pendingFragmentTransaction);
|
selectMenu(pendingFragmentTransaction);
|
||||||
pendingFragmentTransaction = FragmentsAvailable.UNKNOW;
|
pendingFragmentTransaction = FragmentsAvailable.UNKNOW;
|
||||||
}
|
}
|
||||||
|
@ -1309,7 +1291,7 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
if (readContactsI >= 0 && grantResults[readContactsI] == PackageManager.PERMISSION_GRANTED) {
|
if (readContactsI >= 0 && grantResults[readContactsI] == PackageManager.PERMISSION_GRANTED) {
|
||||||
ContactsManager.getInstance().enableContactsAccess();
|
ContactsManager.getInstance().enableContactsAccess();
|
||||||
if (!ContactsManager.getInstance().contactsFetchedOnce()) {
|
if (!ContactsManager.getInstance().contactsFetchedOnce()) {
|
||||||
ContactsManager.getInstance().fetchContactsAsync();
|
ContactsManager.getInstance().initializeContactManager(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1580,19 +1562,19 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initSideMenu() {
|
public void initSideMenu() {
|
||||||
sideMenu = (DrawerLayout) findViewById(R.id.side_menu);
|
sideMenu = findViewById(R.id.side_menu);
|
||||||
sideMenuItems = new ArrayList<String>();
|
sideMenuItems = new ArrayList<>();
|
||||||
sideMenuItems.add(getResources().getString(R.string.menu_assistant));
|
sideMenuItems.add(getResources().getString(R.string.menu_assistant));
|
||||||
sideMenuItems.add(getResources().getString(R.string.menu_settings));
|
sideMenuItems.add(getResources().getString(R.string.menu_settings));
|
||||||
if (getResources().getBoolean(R.bool.enable_in_app_purchase)) {
|
if (getResources().getBoolean(R.bool.enable_in_app_purchase)) {
|
||||||
sideMenuItems.add(getResources().getString(R.string.inapp));
|
sideMenuItems.add(getResources().getString(R.string.inapp));
|
||||||
}
|
}
|
||||||
sideMenuItems.add(getResources().getString(R.string.menu_about));
|
sideMenuItems.add(getResources().getString(R.string.menu_about));
|
||||||
sideMenuContent = (RelativeLayout) findViewById(R.id.side_menu_content);
|
sideMenuContent = findViewById(R.id.side_menu_content);
|
||||||
sideMenuItemList = (ListView) findViewById(R.id.item_list);
|
sideMenuItemList = findViewById(R.id.item_list);
|
||||||
menu = (ImageView) findViewById(R.id.side_menu_button);
|
menu = findViewById(R.id.side_menu_button);
|
||||||
|
|
||||||
sideMenuItemList.setAdapter(new ArrayAdapter<String>(this, R.layout.side_menu_item_cell, sideMenuItems));
|
sideMenuItemList.setAdapter(new ArrayAdapter<>(this, R.layout.side_menu_item_cell, sideMenuItems));
|
||||||
sideMenuItemList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
sideMenuItemList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
||||||
|
@ -1628,7 +1610,7 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
quitLayout = (RelativeLayout) findViewById(R.id.side_menu_quit);
|
quitLayout = findViewById(R.id.side_menu_quit);
|
||||||
quitLayout.setOnClickListener(new OnClickListener() {
|
quitLayout.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
|
@ -1657,9 +1639,9 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
|
|
||||||
private void displayMainAccount() {
|
private void displayMainAccount() {
|
||||||
defaultAccount.setVisibility(View.VISIBLE);
|
defaultAccount.setVisibility(View.VISIBLE);
|
||||||
ImageView status = (ImageView) defaultAccount.findViewById(R.id.main_account_status);
|
ImageView status = defaultAccount.findViewById(R.id.main_account_status);
|
||||||
TextView address = (TextView) defaultAccount.findViewById(R.id.main_account_address);
|
TextView address = defaultAccount.findViewById(R.id.main_account_address);
|
||||||
TextView displayName = (TextView) defaultAccount.findViewById(R.id.main_account_display_name);
|
TextView displayName = defaultAccount.findViewById(R.id.main_account_display_name);
|
||||||
|
|
||||||
|
|
||||||
ProxyConfig proxy = LinphoneManager.getLc().getDefaultProxyConfig();
|
ProxyConfig proxy = LinphoneManager.getLc().getDefaultProxyConfig();
|
||||||
|
@ -1709,20 +1691,20 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initAccounts() {
|
private void initAccounts() {
|
||||||
accountsList = (ListView) findViewById(R.id.accounts_list);
|
accountsList = findViewById(R.id.accounts_list);
|
||||||
defaultAccount = (RelativeLayout) findViewById(R.id.default_account);
|
defaultAccount = findViewById(R.id.default_account);
|
||||||
}
|
}
|
||||||
|
|
||||||
class AccountsListAdapter extends BaseAdapter {
|
class AccountsListAdapter extends BaseAdapter {
|
||||||
List<ProxyConfig> proxy_list;
|
List<ProxyConfig> proxy_list;
|
||||||
|
|
||||||
AccountsListAdapter() {
|
AccountsListAdapter() {
|
||||||
proxy_list = new ArrayList<ProxyConfig>();
|
proxy_list = new ArrayList<>();
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
proxy_list = new ArrayList<ProxyConfig>();
|
proxy_list = new ArrayList<>();
|
||||||
for (ProxyConfig proxyConfig : LinphoneManager.getLc().getProxyConfigList()) {
|
for (ProxyConfig proxyConfig : LinphoneManager.getLc().getProxyConfigList()) {
|
||||||
if (proxyConfig != LinphoneManager.getLc().getDefaultProxyConfig()) {
|
if (proxyConfig != LinphoneManager.getLc().getDefaultProxyConfig()) {
|
||||||
proxy_list.add(proxyConfig);
|
proxy_list.add(proxyConfig);
|
||||||
|
@ -1747,7 +1729,7 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
}
|
}
|
||||||
|
|
||||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||||
View view = null;
|
View view;
|
||||||
ProxyConfig lpc = (ProxyConfig) getItem(position);
|
ProxyConfig lpc = (ProxyConfig) getItem(position);
|
||||||
if (convertView != null) {
|
if (convertView != null) {
|
||||||
view = convertView;
|
view = convertView;
|
||||||
|
@ -1755,8 +1737,8 @@ public class LinphoneActivity extends LinphoneGenericActivity implements OnClick
|
||||||
view = getLayoutInflater().inflate(R.layout.side_menu_account_cell, parent, false);
|
view = getLayoutInflater().inflate(R.layout.side_menu_account_cell, parent, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageView status = (ImageView) view.findViewById(R.id.account_status);
|
ImageView status = view.findViewById(R.id.account_status);
|
||||||
TextView address = (TextView) view.findViewById(R.id.account_address);
|
TextView address = view.findViewById(R.id.account_address);
|
||||||
String sipAddress = lpc.getIdentityAddress().asStringUriOnly();
|
String sipAddress = lpc.getIdentityAddress().asStringUriOnly();
|
||||||
|
|
||||||
address.setText(sipAddress);
|
address.setText(sipAddress);
|
||||||
|
|
|
@ -343,6 +343,7 @@ public class ContactsListFragment extends Fragment implements OnItemClickListene
|
||||||
mContactAdapter.updateDataSet(onlyDisplayLinphoneContacts ? ContactsManager.getInstance().getSIPContacts() : ContactsManager.getInstance().getContacts());
|
mContactAdapter.updateDataSet(onlyDisplayLinphoneContacts ? ContactsManager.getInstance().getSIPContacts() : ContactsManager.getInstance().getContacts());
|
||||||
mContactAdapter.notifyDataSetChanged();
|
mContactAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
contactsFetchInProgress.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void invalidate() {
|
public void invalidate() {
|
||||||
|
|
|
@ -209,10 +209,12 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
||||||
public void initializeContactManager(Activity activity) {
|
public void initializeContactManager(Activity activity) {
|
||||||
if (mActivity == null) {
|
if (mActivity == null) {
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
mActivity.getLoaderManager().initLoader(CONTACTS_LOADER, null, this);
|
} else if (mActivity != activity) {
|
||||||
} else if (mActivity != activity){
|
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
}
|
}
|
||||||
|
if (mContacts.size() == 0 && hasContactsAccess()) {
|
||||||
|
mActivity.getLoaderManager().initLoader(CONTACTS_LOADER, null, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initializeSyncAccount(Activity activity) {
|
public void initializeSyncAccount(Activity activity) {
|
||||||
|
@ -393,7 +395,11 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Loader<Cursor> onCreateLoader(int id, @Nullable Bundle args) {
|
public Loader<Cursor> onCreateLoader(int id, @Nullable Bundle args) {
|
||||||
if (id == CONTACTS_LOADER && hasContactsAccess()) {
|
if (id == CONTACTS_LOADER) {
|
||||||
|
if (!hasContactsAccess()) {
|
||||||
|
Log.w("[ContactsManager] Read contacts permission was denied");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return new CursorLoader(
|
return new CursorLoader(
|
||||||
mActivity,
|
mActivity,
|
||||||
ContactsContract.Data.CONTENT_URI,
|
ContactsContract.Data.CONTENT_URI,
|
||||||
|
|
Loading…
Reference in a new issue