Commit 81dd6d0c authored by Romain Bertozzi's avatar Romain Bertozzi Committed by Romain B.
Browse files

homeactivity: change no network warning

This patch modifies the network error text displayed in the smartlist.
This message now takes the mobile connectivity in account and asks the
activation of the permission if the case is relevant.
By clicking on the message, the user is redirected to the settings
screen where he can grant the permission.

Change-Id: I15705a8efc170e8a3085765bf8dd003f85596ca2
Tuleap: #854
parent b15df396
......@@ -546,10 +546,7 @@ public class HomeActivity extends AppCompatActivity implements LocalService.Call
getFragmentManager().beginTransaction().setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).replace(R.id.main_frame, fContent, "About").addToBackStack("About").commit();
break;
case R.id.menuitem_prefs:
if (fContent instanceof SettingsFragment)
break;
fContent = new SettingsFragment();
getFragmentManager().beginTransaction().setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).replace(R.id.main_frame, fContent, "Prefs").addToBackStack("Prefs").commit();
this.goToSettings();
break;
default:
return false;
......@@ -558,6 +555,27 @@ public class HomeActivity extends AppCompatActivity implements LocalService.Call
return true;
}
public void goToSettings() {
if (fMenu != null) {
MenuItem settingsItem = fMenu.getMenu().findItem(R.id.menuitem_prefs);
if (settingsItem != null) {
settingsItem.setChecked(true);
}
}
if (mNavigationDrawer != null) {
mNavigationDrawer.closeDrawers();
}
if (fContent instanceof SettingsFragment)
return;
fContent = new SettingsFragment();
getFragmentManager()
.beginTransaction()
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.replace(R.id.main_frame, fContent, "Prefs")
.addToBackStack("Prefs")
.commit();
}
@Override
public void onCallContact(final CallContact c) {
Log.w(TAG, "onCallContact " + c.toString() + " " + c.getId() + " " + c.getKey());
......
......@@ -31,6 +31,8 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.RemoteException;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.view.MenuItemCompat;
......@@ -48,6 +50,7 @@ import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
......@@ -91,6 +94,7 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex
private ViewGroup mNewContact;
private ViewGroup mErrorMessagePane;
private TextView mErrorMessageTextView;
private ImageView mErrorImageView;
private Handler mUserInputHandler;
......@@ -136,8 +140,7 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex
if (service.isConnected()) {
mErrorMessagePane.setVisibility(View.GONE);
} else {
mErrorMessagePane.setVisibility(View.VISIBLE);
mErrorMessageTextView.setText(R.string.error_no_network);
this.presentNetworkErrorPanel(service);
}
}
......@@ -320,6 +323,7 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex
mErrorMessagePane = (ViewGroup) inflatedView.findViewById(R.id.error_msg_pane);
mErrorMessageTextView = (TextView) mErrorMessagePane.findViewById(R.id.error_msg_txt);
mErrorImageView = (ImageView) mErrorMessagePane.findViewById(R.id.error_image_view);
LocalService service = mCallbacks.getService();
if (service != null) {
......@@ -567,4 +571,37 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex
Snackbar.make(getView(), snackbarText, Snackbar.LENGTH_LONG).show();
}
}
private void presentNetworkErrorPanel(@NonNull LocalService service) {
if (service.isMobileNetworkConnectedButNotGranted()) {
this.showErrorPanel(R.string.error_mobile_network_available_but_disabled,
true,
R.drawable.ic_settings_white_48dp,
new View.OnClickListener() {
@Override
public void onClick(View v) {
Activity activity = getActivity();
if (activity != null && activity instanceof HomeActivity) {
HomeActivity homeActivity = (HomeActivity)activity;
homeActivity.goToSettings();
}
}
});
}
else {
this.showErrorPanel(R.string.error_no_network, false, 0, null);
}
}
private void showErrorPanel(final int textResId,
final boolean showImage,
final int imageResId,
@Nullable View.OnClickListener clickListener) {
mErrorMessagePane.setVisibility(View.VISIBLE);
mErrorMessagePane.setOnClickListener(clickListener);
mErrorMessageTextView.setText(textResId);
int visibility = (showImage) ? View.VISIBLE : View.GONE;
mErrorImageView.setVisibility(visibility);
mErrorImageView.setImageResource(imageResId);
}
}
......@@ -179,6 +179,9 @@ public class LocalService extends Service implements SharedPreferences.OnSharedP
public boolean isWifiConnected() {
return isWifiConn;
}
public boolean isMobileNetworkConnectedButNotGranted() {
return (!canUseMobile && isMobileConn);
}
public Conference placeCall(SipCall call) {
Conference conf = null;
......
......@@ -36,16 +36,28 @@ along with this program; if not, write to the Free Software
android:layout_alignParentTop="true"
android:background="#e57373"
android:padding="16dp"
android:visibility="gone">
android:visibility="visible">
<ImageView
android:layout_width="28dp"
android:layout_height="28dp"
android:id="@+id/error_image_view"
android:src="@drawable/ic_settings_white_48dp"
android:scaleType="fitCenter"
android:layout_gravity="right"
android:layout_alignParentEnd="true" />
<TextView
android:id="@+id/error_msg_txt"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="14sp"
android:gravity="center_vertical|center_horizontal"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textColor="@color/text_color_primary"
android:textSize="14sp" />
android:layout_marginLeft="26dp"
android:layout_marginRight="26dp" />
</RelativeLayout>
......
......@@ -42,6 +42,7 @@ along with this program; if not, write to the Free Software
<string name="title_section0">Dial</string>
<string name="title_activity_sflphone_home">Ring</string>
<string name="error_no_network">No network connectivity</string>
<string name="error_mobile_network_available_but_disabled">Please grant access to cellular network in the settings screen.</string>
<!-- AB menus -->
<string name="ab_account_creation">New account</string>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment