forked from ramamergim/InstaApp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 87dcc75
Showing
75 changed files
with
2,400 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 26 | ||
defaultConfig { | ||
applicationId "com.mergimrama.instaapp" | ||
minSdkVersion 18 | ||
targetSdkVersion 26 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation 'com.android.support:appcompat-v7:27.0.2' | ||
implementation 'com.android.support.constraint:constraint-layout:1.0.2' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'com.android.support.test:runner:1.0.1' | ||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' | ||
compile 'com.squareup.okhttp3:okhttp:3.9.1' | ||
implementation 'com.github.bumptech.glide:glide:4.4.0' | ||
annotationProcessor 'com.github.bumptech.glide:compiler:4.4.0' | ||
} |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
26 changes: 26 additions & 0 deletions
26
app/src/androidTest/java/com/mergimrama/instaapp/ExampleInstrumentedTest.java
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.mergimrama.instaapp; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() throws Exception { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.mergimrama.instaapp", appContext.getPackageName()); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.mergimrama.instaapp"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET"/> | ||
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/> | ||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity" | ||
android:label="Newsfeed"> | ||
<!--<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter>--> | ||
</activity> | ||
<activity android:name=".UIActivity.LoginActivity" | ||
android:theme="@style/AppTheme.NoActionBar"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity android:name=".UIActivity.RegisterAccountActivity" | ||
android:theme="@style/AppTheme.NoActionBar"/> | ||
<activity android:name=".UIActivity.PostFeedActivity" | ||
android:label="Your Post" /> | ||
</application> | ||
|
||
</manifest> |
53 changes: 53 additions & 0 deletions
53
app/src/main/java/com/mergimrama/instaapp/AddPostAsyncTask.java
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.mergimrama.instaapp; | ||
|
||
import android.os.AsyncTask; | ||
|
||
import com.mergimrama.instaapp.callbacks.AddPostCallback; | ||
import com.mergimrama.instaapp.model.AddPostResponse; | ||
|
||
import org.json.JSONException; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Created by Mergim on 19-Dec-17. | ||
*/ | ||
|
||
public class AddPostAsyncTask extends AsyncTask <String, String, String> { | ||
AddPostCallback addPostCallback; | ||
String imageUrl; | ||
String pershkrimi; | ||
|
||
public AddPostAsyncTask(AddPostCallback addPostCallback, String imageUrl, String pershkrimi) { | ||
this.addPostCallback = addPostCallback; | ||
this.imageUrl = imageUrl; | ||
this.pershkrimi = pershkrimi; | ||
} | ||
|
||
@Override | ||
protected void onPreExecute() { | ||
super.onPreExecute(); | ||
} | ||
|
||
@Override | ||
protected String doInBackground(String... strings) { | ||
try { | ||
return ApiService.postImage(strings[0], imageUrl, pershkrimi); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
protected void onPostExecute(String s) { | ||
super.onPostExecute(s); | ||
try { | ||
AddPostResponse addPostResponse = new AddPostResponse(s); | ||
addPostCallback.onAddPostResponse(addPostResponse.getAddPost()); | ||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
System.out.println(s); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.mergimrama.instaapp; | ||
|
||
/** | ||
* Created by Mergim on 17-Dec-17. | ||
*/ | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import okhttp3.MediaType; | ||
import okhttp3.MultipartBody; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
import okhttp3.RequestBody; | ||
import okhttp3.Response; | ||
|
||
public class ApiService { | ||
public static OkHttpClient client = new OkHttpClient(); | ||
|
||
public static String get(String url) throws IOException { | ||
Request request = new Request.Builder() | ||
.url(url) | ||
.build(); | ||
|
||
Response response = client.newCall(request).execute(); | ||
return response.body().string(); | ||
} | ||
|
||
private static final MediaType MEDIA_TYPE_PNG = MediaType.parse("image/*"); | ||
|
||
public static String uploadImage(File image, String url) throws IOException { | ||
RequestBody requestBody = new MultipartBody.Builder() | ||
.setType(MultipartBody.FORM) | ||
.addFormDataPart("image", image.getName(), RequestBody.create(MEDIA_TYPE_PNG, image)) | ||
.build(); | ||
|
||
Request request = new Request.Builder().url(url) | ||
.post(requestBody).build(); | ||
|
||
Response response = client.newCall(request).execute(); | ||
return response.body().string(); | ||
} | ||
|
||
public static String postImage(String BASE_URLandRoute, String imagePath, String pershkrimi) throws IOException { | ||
RequestBody requestBody = new MultipartBody.Builder() | ||
.setType(MultipartBody.FORM) | ||
.addFormDataPart("user_id", AppPreferences.getUserId() + "") | ||
.addFormDataPart("image_path", imagePath) | ||
.addFormDataPart("pershkrimi", pershkrimi) | ||
.build(); | ||
|
||
Request request = new Request.Builder() | ||
.url(BASE_URLandRoute) | ||
.post(requestBody) | ||
.build(); | ||
|
||
Response response = client.newCall(request).execute(); | ||
return response.body().string(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/mergimrama/instaapp/AppPreferences.java
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.mergimrama.instaapp; | ||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
|
||
/** | ||
* Created by Mergim on 20-Dec-17. | ||
*/ | ||
|
||
public class AppPreferences { | ||
public static final String SHARED_PREFS = "mySharedPref"; | ||
public static final String USER_ID = "userId"; | ||
private static SharedPreferences prefs; | ||
|
||
public static void init(Context context) { | ||
prefs = context.getSharedPreferences(SHARED_PREFS, Context.MODE_PRIVATE); | ||
} | ||
|
||
public static void saveUserId (String userId) { | ||
prefs.edit().putString(USER_ID, userId).commit(); | ||
} | ||
|
||
public static String getUserId() { | ||
return prefs.getString(USER_ID, ""); | ||
} | ||
} |
Oops, something went wrong.