├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── drawable-v24
│ │ │ │ ├── success.png
│ │ │ │ ├── stopwatch.png
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── drawable-hdpi
│ │ │ │ └── ic_action_refresh.png
│ │ │ ├── drawable-mdpi
│ │ │ │ └── ic_action_refresh.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ └── ic_action_refresh.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ └── ic_action_refresh.png
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── menu
│ │ │ │ └── menu_main.xml
│ │ │ ├── layout
│ │ │ │ ├── names.xml
│ │ │ │ └── activity_main.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── java
│ │ │ └── info
│ │ │ │ └── blogbasbas
│ │ │ │ └── fromoflinetoonline
│ │ │ │ ├── network
│ │ │ │ ├── ApiInterface.java
│ │ │ │ └── ApiClient.java
│ │ │ │ ├── pojo
│ │ │ │ ├── Nama.java
│ │ │ │ └── ResponseInsert.java
│ │ │ │ ├── adapter
│ │ │ │ └── NameAdapter.java
│ │ │ │ ├── db
│ │ │ │ └── DatabaseHelper.java
│ │ │ │ ├── reciever
│ │ │ │ └── NetworkStateChecker.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── info
│ │ │ └── blogbasbas
│ │ │ └── fromoflinetoonline
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── info
│ │ └── blogbasbas
│ │ └── fromoflinetoonline
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
└── vcs.xml
├── gradle.properties
├── oflinetoonline
├── send.php
└── names.sql
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | FromOflineToOnline
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gandhi-wibowo/data-android-Offline-to-Online-/master/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/success.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gandhi-wibowo/data-android-Offline-to-Online-/master/app/src/main/res/drawable-v24/success.png
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 10dp
4 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/stopwatch.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gandhi-wibowo/data-android-Offline-to-Online-/master/app/src/main/res/drawable-v24/stopwatch.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gandhi-wibowo/data-android-Offline-to-Online-/master/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gandhi-wibowo/data-android-Offline-to-Online-/master/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gandhi-wibowo/data-android-Offline-to-Online-/master/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gandhi-wibowo/data-android-Offline-to-Online-/master/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gandhi-wibowo/data-android-Offline-to-Online-/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gandhi-wibowo/data-android-Offline-to-Online-/master/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gandhi-wibowo/data-android-Offline-to-Online-/master/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_action_refresh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gandhi-wibowo/data-android-Offline-to-Online-/master/app/src/main/res/drawable-hdpi/ic_action_refresh.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_action_refresh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gandhi-wibowo/data-android-Offline-to-Online-/master/app/src/main/res/drawable-mdpi/ic_action_refresh.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gandhi-wibowo/data-android-Offline-to-Online-/master/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gandhi-wibowo/data-android-Offline-to-Online-/master/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_action_refresh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gandhi-wibowo/data-android-Offline-to-Online-/master/app/src/main/res/drawable-xhdpi/ic_action_refresh.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_action_refresh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gandhi-wibowo/data-android-Offline-to-Online-/master/app/src/main/res/drawable-xxhdpi/ic_action_refresh.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gandhi-wibowo/data-android-Offline-to-Online-/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Feb 27 11:21:14 ICT 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/info/blogbasbas/fromoflinetoonline/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package info.blogbasbas.fromoflinetoonline;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/info/blogbasbas/fromoflinetoonline/network/ApiInterface.java:
--------------------------------------------------------------------------------
1 | package info.blogbasbas.fromoflinetoonline.network;
2 |
3 |
4 | import info.blogbasbas.fromoflinetoonline.pojo.ResponseInsert;
5 | import retrofit2.Call;
6 | import retrofit2.http.FormUrlEncoded;
7 | import retrofit2.http.Field;
8 | import retrofit2.http.FormUrlEncoded;
9 | import retrofit2.http.POST;
10 |
11 |
12 | public interface ApiInterface {
13 | @FormUrlEncoded
14 | @POST("send.php")
15 | Call insertName(@Field("name") String nama);
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/info/blogbasbas/fromoflinetoonline/network/ApiClient.java:
--------------------------------------------------------------------------------
1 | package info.blogbasbas.fromoflinetoonline.network;
2 |
3 |
4 |
5 | import retrofit2.Retrofit;
6 | import retrofit2.converter.gson.GsonConverterFactory;
7 |
8 |
9 | public class ApiClient {
10 |
11 | private static Retrofit retrofit = null;
12 |
13 | public static Retrofit getClient(){
14 | if (retrofit == null){
15 | retrofit = new Retrofit.Builder()
16 | .baseUrl("http://192.168.1.106/oflinetoonline/")
17 | .addConverterFactory(GsonConverterFactory.create())
18 | .build();
19 | }
20 | return retrofit;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/info/blogbasbas/fromoflinetoonline/pojo/Nama.java:
--------------------------------------------------------------------------------
1 | package info.blogbasbas.fromoflinetoonline.pojo;
2 |
3 | /**
4 | * Created by User on 26/02/2018.
5 | */
6 |
7 | public class Nama {
8 | private String name;
9 | private int status;
10 |
11 | public Nama(String name, int status) {
12 | this.name = name;
13 | this.status = status;
14 | }
15 |
16 | public String getName() {
17 | return name;
18 | }
19 |
20 | public void setName(String name) {
21 | this.name = name;
22 | }
23 |
24 | public int getStatus() {
25 | return status;
26 | }
27 |
28 | public void setStatus(int status) {
29 | this.status = status;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/names.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/info/blogbasbas/fromoflinetoonline/pojo/ResponseInsert.java:
--------------------------------------------------------------------------------
1 | package info.blogbasbas.fromoflinetoonline.pojo;
2 |
3 |
4 | import com.google.gson.annotations.SerializedName;
5 |
6 |
7 | public class ResponseInsert{
8 |
9 | @SerializedName("error")
10 | private boolean error;
11 |
12 | @SerializedName("message")
13 | private String message;
14 |
15 | public void setError(boolean error){
16 | this.error = error;
17 | }
18 |
19 | public boolean isError(){
20 | return error;
21 | }
22 |
23 | public void setMessage(String message){
24 | this.message = message;
25 | }
26 |
27 | public String getMessage(){
28 | return message;
29 | }
30 |
31 | @Override
32 | public String toString(){
33 | return
34 | "ResponseInsert{" +
35 | "error = '" + error + '\'' +
36 | ",message = '" + message + '\'' +
37 | "}";
38 | }
39 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/info/blogbasbas/fromoflinetoonline/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package info.blogbasbas.fromoflinetoonline;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("info.blogbasbas.fromoflinetoonline", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | defaultConfig {
6 | applicationId "info.blogbasbas.fromoflinetoonline"
7 | minSdkVersion 15
8 | targetSdkVersion 26
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'com.android.support:appcompat-v7:26.1.0'
24 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
25 | testImplementation 'junit:junit:4.12'
26 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
28 | compile 'com.squareup.retrofit2:retrofit:2.3.0'
29 | compile 'com.squareup.retrofit2:converter-gson:2.3.0'
30 | compile 'com.jakewharton:butterknife:8.8.1'
31 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
21 |
22 |
28 |
29 |
30 |
31 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/oflinetoonline/send.php:
--------------------------------------------------------------------------------
1 | connect_error) {
17 | die("Connection failed: " . $conn->connect_error);
18 | }
19 |
20 | //making an array to store the response
21 | $response = array();
22 |
23 | //if there is a post request move ahead
24 | if($_SERVER['REQUEST_METHOD']=='POST'){
25 |
26 | //getting the name from request
27 | $name = $_POST['name'];
28 |
29 | //creating a statement to insert to database
30 | $stmt = $conn->prepare("INSERT INTO names (name) VALUES (?)");
31 |
32 | //binding the parameter to statement
33 | $stmt->bind_param("s", $name);
34 |
35 | //if data inserts successfully
36 | if($stmt->execute()){
37 | //making success response
38 | $response['error'] = false;
39 | $response['message'] = ' Name saved successfully';
40 | }else{
41 | //if not making failure response
42 | $response['error'] = true;
43 | $response['message'] = 'Please try later';
44 | }
45 |
46 | }else{
47 | $response['error'] = true;
48 | $response['message'] = "Invalid request";
49 | }
50 |
51 | //displaying the data in json format
52 | echo json_encode($response);
--------------------------------------------------------------------------------
/oflinetoonline/names.sql:
--------------------------------------------------------------------------------
1 | -- phpMyAdmin SQL Dump
2 | -- version 4.7.4
3 | -- https://www.phpmyadmin.net/
4 | --
5 | -- Host: 127.0.0.1
6 | -- Generation Time: Feb 27, 2018 at 05:34 AM
7 | -- Server version: 10.1.28-MariaDB
8 | -- PHP Version: 5.6.32
9 |
10 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
11 | SET AUTOCOMMIT = 0;
12 | START TRANSACTION;
13 | SET time_zone = "+00:00";
14 |
15 |
16 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
17 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
18 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
19 | /*!40101 SET NAMES utf8mb4 */;
20 |
21 | --
22 | -- Database: `android`
23 | --
24 |
25 | -- --------------------------------------------------------
26 |
27 | --
28 | -- Table structure for table `names`
29 | --
30 |
31 | CREATE TABLE `names` (
32 | `id` int(3) NOT NULL,
33 | `name` varchar(100) NOT NULL
34 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
35 |
36 | --
37 | -- Indexes for dumped tables
38 | --
39 |
40 | --
41 | -- Indexes for table `names`
42 | --
43 | ALTER TABLE `names`
44 | ADD PRIMARY KEY (`id`);
45 |
46 | --
47 | -- AUTO_INCREMENT for dumped tables
48 | --
49 |
50 | --
51 | -- AUTO_INCREMENT for table `names`
52 | --
53 | ALTER TABLE `names`
54 | MODIFY `id` int(3) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=32;
55 | COMMIT;
56 |
57 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
58 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
59 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
60 |
--------------------------------------------------------------------------------
/app/src/main/java/info/blogbasbas/fromoflinetoonline/adapter/NameAdapter.java:
--------------------------------------------------------------------------------
1 | package info.blogbasbas.fromoflinetoonline.adapter;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.ArrayAdapter;
8 | import android.widget.ImageView;
9 | import android.widget.TextView;
10 |
11 | import java.util.List;
12 |
13 | import info.blogbasbas.fromoflinetoonline.R;
14 | import info.blogbasbas.fromoflinetoonline.pojo.Nama;
15 |
16 | /**
17 | * Created by User on 26/02/2018.
18 | */
19 |
20 | public class NameAdapter extends ArrayAdapter {
21 | private List names;
22 | private Context context;
23 |
24 | public NameAdapter(Context context, int resource, Listnames) {
25 | super(context, resource, names);
26 | this.context= context;
27 | this.names=names;
28 |
29 | }
30 |
31 | @Override
32 | public View getView (int position, View convertview, ViewGroup parent){
33 | //getting the layoutinflater
34 | LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
35 |
36 | //getting listview itmes
37 | View listViewItem = inflater.inflate(R.layout.names, null, true);
38 | TextView textViewName = (TextView) listViewItem.findViewById(R.id.textViewName);
39 | ImageView imageViewStatus = (ImageView) listViewItem.findViewById(R.id.imageViewStatus);
40 |
41 | //getting the current name
42 | Nama name = names.get(position);
43 |
44 | //setting the name to textview
45 | textViewName.setText(name.getName());
46 |
47 | if (name.getStatus()==0) {
48 | imageViewStatus.setBackgroundResource(R.drawable.stopwatch);
49 | }
50 | else
51 | imageViewStatus.setBackgroundResource(R.drawable.success);
52 |
53 | return listViewItem;
54 | }
55 | }
56 |
57 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/info/blogbasbas/fromoflinetoonline/db/DatabaseHelper.java:
--------------------------------------------------------------------------------
1 | package info.blogbasbas.fromoflinetoonline.db;
2 |
3 | import android.content.ContentValues;
4 | import android.content.Context;
5 | import android.database.Cursor;
6 | import android.database.sqlite.SQLiteDatabase;
7 | import android.database.sqlite.SQLiteOpenHelper;
8 |
9 | /**
10 | * Created by User on 26/02/2018.
11 | */
12 |
13 | public class DatabaseHelper extends SQLiteOpenHelper {
14 | public static final String DB_NAME = "NamesDb";
15 | public static final String TABLE_NAME = "names";
16 | public static final String COLUMN_ID = "id";
17 | public static final String COLUMN_NAME = "name";
18 | public static final String COLUMN_STATUS = "status";
19 |
20 | public static final int DB_VERSION = 1;
21 |
22 |
23 | public DatabaseHelper(Context context) {
24 | super(context,DB_NAME,null,DB_VERSION);
25 | }
26 |
27 |
28 | @Override
29 | public void onCreate(SQLiteDatabase db) {
30 | String sql = "CREATE TABLE "+ TABLE_NAME
31 | +"(" + COLUMN_ID+
32 | " INTEGER PRIMARY KEY AUTOINCREMENT, "+COLUMN_NAME+
33 | " VARCHAR, " +COLUMN_STATUS +
34 | " TINYINT);";
35 | db.execSQL(sql);
36 | }
37 |
38 | @Override
39 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
40 | String sql = "DROP TABLE IF EXISTS Persons";
41 | db.execSQL(sql);
42 | onCreate(db);
43 |
44 | }
45 | public boolean addName (String name, int status){
46 | SQLiteDatabase db = this.getWritableDatabase();
47 | ContentValues values = new ContentValues();
48 | values.put(COLUMN_NAME,name);
49 | values.put(COLUMN_STATUS,status);
50 | db.insert(TABLE_NAME,null,values);
51 | db.close();
52 | return true;
53 | }
54 | public boolean updateNameStatus (int id, int status){
55 | SQLiteDatabase db = this.getWritableDatabase();
56 | ContentValues values = new ContentValues();
57 | values.put(COLUMN_STATUS,status);
58 | db.update(TABLE_NAME,values,COLUMN_ID +"=" +id,null);
59 | db.close();
60 | return true;
61 | }
62 | public Cursor getNames (){
63 | SQLiteDatabase db = this.getReadableDatabase();
64 | String sql = "SELECT * FROM "+TABLE_NAME + " ORDER BY " +COLUMN_ID + " ASC;";
65 | Cursor cursor = db.rawQuery(sql,null);
66 | return cursor;
67 | }
68 | public Cursor getUnsyncedNames (){
69 | SQLiteDatabase db = this.getReadableDatabase();
70 | String sql = "SELECT * FROM "+TABLE_NAME + " WHERE " +COLUMN_STATUS + " = 0;";
71 | Cursor cursor = db.rawQuery(sql, null);
72 | return cursor;
73 |
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/app/src/main/java/info/blogbasbas/fromoflinetoonline/reciever/NetworkStateChecker.java:
--------------------------------------------------------------------------------
1 | package info.blogbasbas.fromoflinetoonline.reciever;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.database.Cursor;
7 | import android.net.ConnectivityManager;
8 | import android.net.NetworkInfo;
9 |
10 | import info.blogbasbas.fromoflinetoonline.MainActivity;
11 | import info.blogbasbas.fromoflinetoonline.db.DatabaseHelper;
12 | import info.blogbasbas.fromoflinetoonline.network.ApiClient;
13 | import info.blogbasbas.fromoflinetoonline.network.ApiInterface;
14 | import info.blogbasbas.fromoflinetoonline.pojo.ResponseInsert;
15 | import retrofit2.Call;
16 | import retrofit2.Callback;
17 | import retrofit2.Response;
18 |
19 | /**
20 | * Created by User on 27/02/2018.
21 | */
22 |
23 | public class NetworkStateChecker extends BroadcastReceiver {
24 | private Context context;
25 | private DatabaseHelper db;
26 | @Override
27 | public void onReceive(Context context, Intent intent) {
28 | this.context = context;
29 | db = new DatabaseHelper(context);
30 |
31 | //cek jaringan
32 | ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
33 | NetworkInfo acNetworkInfo = cm.getActiveNetworkInfo();
34 | //cek jaringan
35 | if (acNetworkInfo !=null){
36 | if (acNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI || acNetworkInfo.getType() == ConnectivityManager.TYPE_MOBILE){
37 |
38 | Cursor cursor = db.getUnsyncedNames();
39 | if (cursor.moveToFirst()){
40 | do {
41 | saveName(
42 | cursor.getInt(cursor.getColumnIndex(DatabaseHelper.COLUMN_ID)),
43 | cursor.getString(cursor.getColumnIndex(DatabaseHelper.COLUMN_NAME))
44 | );
45 | }
46 | while (cursor.moveToNext());
47 | }
48 | }
49 | }
50 | }
51 |
52 | private void saveName(final int id, final String nama) {
53 | ApiInterface service = ApiClient.getClient().create(ApiInterface.class);
54 | Call call = service.insertName(nama);
55 | call.enqueue(new Callback() {
56 | @Override
57 | public void onResponse(Call call, Response response) {
58 | boolean error = response.body().isError();
59 | if (error == false) {
60 | db.updateNameStatus(id, MainActivity.NAME_SYNCED_WITH_SERVER);
61 |
62 | //sending the broadcast to refresh the list
63 | context.sendBroadcast(new Intent(MainActivity.DATA_SAVED_BROADCAST));
64 |
65 | }
66 | }
67 |
68 | @Override
69 | public void onFailure(Call call, Throwable t) {
70 |
71 | }
72 | });
73 | }
74 | }
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/java/info/blogbasbas/fromoflinetoonline/MainActivity.java:
--------------------------------------------------------------------------------
1 | package info.blogbasbas.fromoflinetoonline;
2 |
3 | import android.app.ProgressDialog;
4 | import android.content.BroadcastReceiver;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.content.IntentFilter;
8 | import android.database.Cursor;
9 | import android.net.ConnectivityManager;
10 | import android.os.Bundle;
11 | import android.support.v7.app.AppCompatActivity;
12 | import android.util.Log;
13 | import android.view.Menu;
14 | import android.view.MenuItem;
15 | import android.widget.Button;
16 | import android.widget.EditText;
17 | import android.widget.ListView;
18 | import android.widget.Toast;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | import butterknife.BindView;
24 | import butterknife.ButterKnife;
25 | import butterknife.OnClick;
26 | import info.blogbasbas.fromoflinetoonline.adapter.NameAdapter;
27 | import info.blogbasbas.fromoflinetoonline.db.DatabaseHelper;
28 | import info.blogbasbas.fromoflinetoonline.network.ApiClient;
29 | import info.blogbasbas.fromoflinetoonline.network.ApiInterface;
30 | import info.blogbasbas.fromoflinetoonline.pojo.Nama;
31 | import info.blogbasbas.fromoflinetoonline.pojo.ResponseInsert;
32 | import info.blogbasbas.fromoflinetoonline.reciever.NetworkStateChecker;
33 | import retrofit2.Call;
34 | import retrofit2.Callback;
35 | import retrofit2.Response;
36 |
37 | public class MainActivity extends AppCompatActivity {
38 |
39 | @BindView(R.id.editTextName)
40 | EditText editTextName;
41 | @BindView(R.id.buttonSave)
42 | Button buttonSave;
43 | @BindView(R.id.listViewNames)
44 | ListView listViewNames;
45 | private DatabaseHelper db;
46 | private List names;
47 | public static final int NAME_SYNCED_WITH_SERVER = 1;
48 | public static final int NAME_NOT_SYNCED_WITH_SERVER = 0;
49 |
50 | //a broadcast to know weather the data is synced or not
51 | public static final String DATA_SAVED_BROADCAST = "info.blogbasbas.oflinetoonlineretrofit";
52 |
53 | //Broadcast receiver to know the sync status
54 | private BroadcastReceiver broadcastReceiver;
55 |
56 | //adapterobject for list view
57 | private NameAdapter nameAdapter;
58 | @Override
59 | protected void onCreate(Bundle savedInstanceState) {
60 | super.onCreate(savedInstanceState);
61 | setContentView(R.layout.activity_main);
62 | ButterKnife.bind(this);
63 | registerReceiver(new NetworkStateChecker(), new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
64 |
65 | db = new DatabaseHelper(this);
66 | names = new ArrayList<>();
67 | loadNames();
68 | broadcastReceiver = new BroadcastReceiver(){
69 | @Override
70 | public void onReceive(Context context, Intent intent) {
71 | loadNames();
72 | }
73 | };
74 |
75 | registerReceiver(broadcastReceiver, new IntentFilter(DATA_SAVED_BROADCAST));
76 | }
77 |
78 | private void loadNames() {
79 | names.clear();
80 | Cursor cursor= db.getNames();
81 | if (cursor.moveToFirst()){
82 | do {
83 | Nama name = new Nama(
84 | cursor.getString(cursor.getColumnIndex(DatabaseHelper.COLUMN_NAME)),
85 | cursor.getInt(cursor.getColumnIndex(DatabaseHelper.COLUMN_STATUS))
86 | );
87 | names.add(name);
88 | }while (cursor.moveToNext());
89 | }
90 | nameAdapter = new NameAdapter(this,R.layout.names,names);
91 | listViewNames.setAdapter(nameAdapter);
92 | }
93 | private void refreshList(){
94 | nameAdapter.notifyDataSetChanged();
95 | }
96 | @OnClick(R.id.buttonSave)
97 | public void onViewClicked() {
98 | final String nama = editTextName.getText().toString();
99 | final ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
100 | progressDialog.setMessage("Saving Name . . .");
101 | progressDialog.show();
102 | try {
103 | ApiInterface service = ApiClient.getClient().create(ApiInterface.class);
104 | retrofit2.Call call = service.insertName(nama);
105 | call.enqueue(new Callback() {
106 | @Override
107 | public void onResponse(Call call, Response response) {
108 | /*
109 |
110 | try {
111 | JSONObject obj = new JSONObject(String.valueOf(response));
112 | if (!obj.getBoolean("error")){
113 | saveNameToLocalStorage(nama, NAME_SYNCED_WITH_SERVER);
114 | progressDialog.dismiss();
115 | refreshList();
116 | }else {
117 | //if there is some error
118 | //saving the name to sqlite with status unsynced
119 | refreshList();
120 | saveNameToLocalStorage(nama, NAME_NOT_SYNCED_WITH_SERVER);
121 | }
122 | } catch (JSONException e) {
123 | e.printStackTrace();
124 | }*/
125 | /*
126 |
127 | */
128 |
129 | boolean error = response.body().isError();
130 | if (error == false) {
131 | saveNameToLocalStorage(nama, NAME_SYNCED_WITH_SERVER);
132 | startActivity(new Intent(MainActivity.this, MainActivity.class));
133 | progressDialog.dismiss();
134 | Toast.makeText(MainActivity.this, "sukses insert data", Toast.LENGTH_SHORT).show();
135 | } else {
136 | progressDialog.dismiss();
137 | saveNameToLocalStorage(nama, NAME_NOT_SYNCED_WITH_SERVER);
138 | Toast.makeText(MainActivity.this, "gagal insert data", Toast.LENGTH_SHORT).show();
139 | }
140 |
141 | }
142 |
143 | @Override
144 | public void onFailure(Call call, Throwable t) {
145 | saveNameToLocalStorage(nama, NAME_NOT_SYNCED_WITH_SERVER);
146 | progressDialog.dismiss();
147 | }
148 | });
149 |
150 | }catch (Exception e){
151 | Toast.makeText(this, "Erro "+e.toString(), Toast.LENGTH_SHORT).show();
152 | Log.d("", "onViewClicked: "+e.toString());
153 | }
154 | }
155 |
156 | private void saveNameToLocalStorage(String name, int status) {
157 | editTextName.setText("");
158 | db.addName(name,status);
159 | Nama n = new Nama(name,status);
160 | names.add(n);
161 | refreshList();
162 | }
163 |
164 | @Override
165 | public boolean onOptionsItemSelected(MenuItem item) {
166 | int id = item.getItemId();
167 |
168 | //noinspection SimplifiableIfStatement
169 | if (id == R.id.menumain){
170 | refreshList();
171 | startActivity(new Intent(MainActivity.this, MainActivity.class));
172 |
173 | }
174 |
175 | return super.onOptionsItemSelected(item);
176 | }
177 |
178 | @Override
179 | public boolean onCreateOptionsMenu(Menu menu) {
180 | getMenuInflater().inflate(R.menu.menu_main, menu);
181 | return true;
182 | }
183 | }
184 |
--------------------------------------------------------------------------------