This repository has been archived by the owner on Nov 8, 2018. It is now read-only.
forked from peacecorps/malaria-app-android
-
Notifications
You must be signed in to change notification settings - Fork 110
fixed app crash when no qty given in medicine and requested sms permi… #374
Open
shikherjaiswal
wants to merge
1
commit into
systers:develop
Choose a base branch
from
shikherjaiswal:issue#356_#347
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
package com.peacecorps.malaria.ui.medicine_store; | ||
|
||
import android.Manifest; | ||
import android.app.Dialog; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.support.v4.app.ActivityCompat; | ||
import android.support.v4.content.ContextCompat; | ||
import android.telephony.SmsManager; | ||
import android.text.Html; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.EditText; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
import com.peacecorps.malaria.R; | ||
import com.peacecorps.malaria.ui.base.BaseFragment; | ||
|
@@ -35,6 +40,8 @@ public class MedicineStoreFragment extends BaseFragment implements MedicineMvpVi | |
TextView daysLeft; | ||
private Context context; | ||
private MedicineStorePresenter<MedicineStoreFragment> presenter; | ||
private int PERMISSIONS_REQUEST_SEND_SMS = 7; | ||
private boolean smsPermissionGranted = false; | ||
|
||
@Nullable | ||
@Override | ||
|
@@ -138,18 +145,44 @@ public void onClick(View view) { | |
} | ||
}); | ||
//implement the message button | ||
//Todo ask for SEND Message permission | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not related to my changes |
||
orderMedicineDialog.findViewById(R.id.btn_order_by_msg).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
if (presenter.checkMedicineNumberValidity(quantity.getText().toString().trim())) { | ||
if (!presenter.checkMedicineNumberValidity(quantity.getText().toString().trim())) { | ||
quantity.setError("Quantity Required"); | ||
quantity.requestFocus(); | ||
} else { | ||
SmsManager smsManager = SmsManager.getDefault(); | ||
smsManager.sendTextMessage("123", null, | ||
presenter.getMessageBodyForOrder() + | ||
Integer.parseInt(quantity.getText().toString()), null, null); | ||
orderMedicineDialog.dismiss(); | ||
//Entered Order quantity is greater than 0 | ||
if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.SEND_SMS) | ||
!= PackageManager.PERMISSION_GRANTED) { | ||
// Permission is not granted | ||
// Ask for permission | ||
ActivityCompat.requestPermissions(getActivity(), | ||
new String[]{Manifest.permission.SEND_SMS}, | ||
PERMISSIONS_REQUEST_SEND_SMS); | ||
|
||
} | ||
else{ | ||
smsPermissionGranted = true; | ||
} | ||
|
||
if(smsPermissionGranted) { | ||
SmsManager smsManager = SmsManager.getDefault(); | ||
//Sms cannot parse html tags so remove them and use appropriate alternative | ||
String message = (presenter.getMessageBodyForOrder() +Integer.parseInt(quantity.getText().toString())).toString(); | ||
String patternRegex = "<[/]*b>"; // To match <b> and </b> | ||
message = message.replaceAll("<br>","\n"); | ||
message = message.replaceAll(patternRegex," "); | ||
String phoneNo = "121"; | ||
smsManager.sendTextMessage(phoneNo, null,message, null, null); | ||
Toast.makeText(getActivity(), "Message sent", Toast.LENGTH_LONG).show(); | ||
orderMedicineDialog.dismiss(); | ||
} | ||
else{ | ||
//Show Toast message | ||
Toast.makeText(getActivity(), "Cannot use this feature without Send SMS permission", Toast.LENGTH_LONG).show(); | ||
} | ||
} | ||
} | ||
}); | ||
|
@@ -210,4 +243,14 @@ public void onClick(View view) { | |
settingsDialog.show(); | ||
|
||
} | ||
@Override | ||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) | ||
{ | ||
super.onRequestPermissionsResult(requestCode, permissions, grantResults); | ||
|
||
if (requestCode == PERMISSIONS_REQUEST_SEND_SMS && grantResults.length >0 && grantResults[0] == PackageManager.PERMISSION_GRANTED ) { | ||
smsPermissionGranted = true; | ||
} | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to my changes