Skip to content

Commit

Permalink
Finished Project
Browse files Browse the repository at this point in the history
  • Loading branch information
ramamergim committed Dec 21, 2017
0 parents commit 87dcc75
Show file tree
Hide file tree
Showing 75 changed files with 2,400 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
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
18 changes: 18 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
31 changes: 31 additions & 0 deletions app/build.gradle
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'
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
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
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());
}
}
39 changes: 39 additions & 0 deletions app/src/main/AndroidManifest.xml
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 app/src/main/java/com/mergimrama/instaapp/AddPostAsyncTask.java
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);
}
}
60 changes: 60 additions & 0 deletions app/src/main/java/com/mergimrama/instaapp/ApiService.java
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 app/src/main/java/com/mergimrama/instaapp/AppPreferences.java
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, "");
}
}
Loading

0 comments on commit 87dcc75

Please sign in to comment.