Skip to content

Commit 76f4cbc

Browse files
committed
v1
1 parent ea60110 commit 76f4cbc

16 files changed

Lines changed: 221 additions & 247 deletions

.idea/DtonatorPreferences.xml

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 Bytes
Binary file not shown.

app/build.gradle

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,15 @@ dependencies {
2525
testImplementation 'junit:junit:4.12'
2626
androidTestImplementation 'com.android.support.test:runner:1.0.2'
2727
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
28-
//networking volley library
29-
implementation 'com.android.volley:volley:1.1.0'
30-
implementation 'com.github.mobtexting:mobtexting-android-sdk:c3e6033d76'
28+
29+
// implementation 'com.github.mobtexting:mobtexting-android-sdk:ea601104d3'
3130
implementation 'com.msg91.sendotp.library:library:3.1'
31+
32+
// Retrofit
33+
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.0'
34+
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
35+
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
36+
implementation 'com.squareup:otto:1.3.8'
37+
implementation 'com.google.code.gson:gson:2.6.2'
38+
3239
}

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
android:roundIcon="@mipmap/ic_launcher_round"
1010
android:supportsRtl="true"
1111
android:theme="@style/AppTheme">
12+
<meta-data android:name="mobtexting.api_key" android:value="@string/mobtextingapikey" />
1213
<activity android:name=".MainActivity">
1314
<intent-filter>
1415
<action android:name="android.intent.action.MAIN" />

app/src/main/java/com/mobtexting/sms/MainActivity.java

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,15 @@
22

33
import android.support.v7.app.AppCompatActivity;
44
import android.os.Bundle;
5-
import android.util.Log;
6-
import android.widget.Toast;
75

8-
import com.mobtexting.Communicator;
9-
import com.mobtexting.event.ErrorEvent;
10-
import com.mobtexting.event.ServerEvent;
11-
import com.squareup.otto.Subscribe;
126

137

14-
public class MainActivity extends AppCompatActivity {
15-
private Communicator communicator;
8+
public class MainActivity extends AppCompatActivity{
9+
1610
@Override
1711
protected void onCreate(Bundle savedInstanceState) {
1812
super.onCreate(savedInstanceState);
1913
setContentView(R.layout.activity_main);
20-
21-
communicator=new Communicator();
22-
communicator.loginPost("sdfsdfsfsdfsdf","dsfsdfsdf","7250705072","MOBTXT");
2314
}
2415

25-
@Subscribe
26-
public void onServerEvent(ServerEvent serverEvent){
27-
Toast.makeText(this, ""+serverEvent.getServerResponse().getMessage(), Toast.LENGTH_SHORT).show();
28-
if(serverEvent.getServerResponse().getUsername() != null){
29-
Toast.makeText(getBaseContext(),serverEvent.getServerResponse().getUsername(),Toast.LENGTH_SHORT).show();
30-
}
31-
Toast.makeText(getBaseContext(),serverEvent.getServerResponse().getMessage(),Toast.LENGTH_SHORT).show();
32-
}
33-
34-
@Subscribe
35-
public void onErrorEvent(ErrorEvent errorEvent){
36-
Toast.makeText(this,""+errorEvent.getErrorMsg(),Toast.LENGTH_SHORT).show();
37-
}
3816
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<resources>
22
<string name="app_name">mobtexting-android-sdk</string>
3+
<string name="mobtextingapikey">gdfgdgdfgfd</string>
34
</resources>

mobtextingsms/src/main/java/com/mobtexting/BusProvider.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

mobtextingsms/src/main/java/com/mobtexting/Communicator.java

Lines changed: 0 additions & 99 deletions
This file was deleted.

mobtextingsms/src/main/java/com/mobtexting/Interface.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.mobtexting;
22

3+
34
import retrofit2.Call;
45
import retrofit2.http.Field;
56
import retrofit2.http.FormUrlEncoded;
@@ -10,15 +11,15 @@
1011
public interface Interface {
1112

1213
@FormUrlEncoded
13-
@POST("/v1/sms")
14+
@POST("/v1/sms/")
1415
Call<ServerResponse> post(
1516
@Field("api_key") String method,
1617
@Field("message") String username,
1718
@Field("mobile_no") String password,
1819
@Field("sender_id") String sender_id
1920
);
2021

21-
@GET("/v1/sms")
22+
@GET("/v1/sms/")
2223
Call<ServerResponse> get(
2324
@Query("method") String method,
2425
@Query("username") String username,
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package com.mobtexting;
2+
3+
import android.content.Context;
4+
import android.content.pm.ApplicationInfo;
5+
import android.content.pm.PackageManager;
6+
import android.os.Bundle;
7+
import android.util.Log;
8+
9+
import java.io.IOException;
10+
import java.lang.annotation.Annotation;
11+
12+
import okhttp3.OkHttpClient;
13+
import okhttp3.ResponseBody;
14+
import okhttp3.logging.HttpLoggingInterceptor;
15+
import retrofit2.Call;
16+
import retrofit2.Callback;
17+
import retrofit2.Converter;
18+
import retrofit2.Response;
19+
import retrofit2.Retrofit;
20+
import retrofit2.converter.gson.GsonConverterFactory;
21+
22+
23+
public class Mobtexting {
24+
private static final String TAG = "Communicator";
25+
private static final String SERVER_URL = "http://api.mobtexting.com";
26+
private Retrofit retrofit;
27+
private String api_key1;
28+
private Context context;
29+
30+
public Mobtexting(Context context){
31+
this.context=context;
32+
}
33+
34+
public void sendSMS(String message, String mobile_no, String senderId, final MobtextingInterface mobtextingInterface) {
35+
try {
36+
ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
37+
Bundle bundle = ai.metaData;
38+
api_key1= bundle.getString("mobtexting.api_key");
39+
}catch (Exception e){
40+
mobtextingInterface.onError(new ModelError("100", "API key", "Dear developer. Don't forget to configure <meta-data android:name=\"mobtexting.api_key\" android:value=\"testValue\"/> in your AndroidManifest.xml file."));
41+
return;
42+
}
43+
if(api_key1!=null&&!api_key1.equals("")) {
44+
45+
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
46+
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
47+
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
48+
httpClient.addInterceptor(logging);
49+
50+
retrofit = new Retrofit.Builder()
51+
.client(httpClient.build())
52+
.addConverterFactory(GsonConverterFactory.create())
53+
.baseUrl(SERVER_URL)
54+
.build();
55+
56+
Interface service = retrofit.create(Interface.class);
57+
58+
Call<ServerResponse> call = service.post(api_key1, message, mobile_no, senderId);
59+
60+
call.enqueue(new Callback<ServerResponse>() {
61+
@Override
62+
public void onResponse(Call<ServerResponse> call, Response<ServerResponse> response) {
63+
// response.isSuccessful() is true if the response code is 2xx
64+
if (response.isSuccessful()) {
65+
Log.e(TAG, response.body().toString());
66+
mobtextingInterface.onResponse(response.body());
67+
} else {
68+
try {
69+
Converter<ResponseBody, ModelError> errorConverter = retrofit.responseBodyConverter(ModelError.class, new Annotation[0]);
70+
ModelError error = errorConverter.convert(response.errorBody());
71+
mobtextingInterface.onError(error);
72+
} catch (IOException e) {
73+
e.printStackTrace();
74+
mobtextingInterface.onError(new ModelError("500", "Something Went Wrong!", "Check your internet connection!/parsing Json exception"));
75+
}
76+
}
77+
}
78+
79+
@Override
80+
public void onFailure(Call<ServerResponse> call, Throwable t) {
81+
mobtextingInterface.onError(new ModelError("500", "No Internet", "Check your internet connection!"));
82+
}
83+
});
84+
}else{
85+
mobtextingInterface.onError(new ModelError("100", "API key", "Dear developer. Don't forget to configure <meta-data android:name=\"mobtexting.api_key\" android:value=\"testValue\"/> in your AndroidManifest.xml file."));
86+
}
87+
}
88+
89+
/*public void loginGet(String username, String password) {
90+
91+
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
92+
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
93+
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
94+
httpClient.addInterceptor(logging);
95+
96+
Retrofit retrofit = new Retrofit.Builder()
97+
.client(httpClient.build())
98+
.addConverterFactory(GsonConverterFactory.create())
99+
.baseUrl(SERVER_URL)
100+
.build();
101+
102+
Interface service = retrofit.create(Interface.class);
103+
104+
Call<ServerResponse> call = service.get("login", username, password);
105+
106+
call.enqueue(new Callback<ServerResponse>() {
107+
@Override
108+
public void onResponse(Call<ServerResponse> call, Response<ServerResponse> response) {
109+
// response.isSuccessful() is true if the response code is 2xx
110+
Log.e(TAG, "Success");
111+
}
112+
113+
@Override
114+
public void onFailure(Call<ServerResponse> call, Throwable t) {
115+
// handle execution failures like no internet connectivity
116+
Log.d("internet",t.getMessage());
117+
}
118+
});
119+
}*/
120+
121+
122+
}
123+

0 commit comments

Comments
 (0)