Skip to content

Commit

Permalink
push notification enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
iMaks99 committed May 3, 2019
1 parent a059b9e commit f81f4f5
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 7 deletions.
10 changes: 6 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
compileSdkVersion 28
Expand All @@ -24,16 +25,17 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0-alpha03'
implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'androidx.cardview:cardview:1.0.0'


implementation 'androidx.legacy:legacy-support-v4:1.0.0-beta01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.firebase:firebase-messaging:17.6.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.2-alpha02'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha02'
androidTestImplementation 'androidx.test:runner:1.2.0-alpha05'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha05'
}
13 changes: 13 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,24 @@

<uses-permission android:name="android.permission.INTERNET" />



<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.NoActionBar">

<service
android:name=".network.MessagingService"
android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>

<activity android:name=".AuthenticationActivity" />
<activity android:name=".MainActivity">
<intent-filter>
Expand All @@ -19,6 +30,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>


</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_authentication);

ActionBar actionBar = getSupportActionBar();
actionBar.hide();
if (actionBar != null)
actionBar.hide();

FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.maks.odooprojects;


import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


/**
* A simple {@link Fragment} subclass.
*/
public class CreateProjectTaskFragment extends Fragment {


public CreateProjectTaskFragment() {
// Required empty public constructor
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_create_project_task, container, false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
Expand All @@ -22,6 +23,7 @@
import android.widget.Toast;

import com.example.maks.odooprojects.network.IGetDataService;
import com.example.maks.odooprojects.network.MessagingService;
import com.example.maks.odooprojects.network.RetrofitClientInstance;


Expand Down Expand Up @@ -60,6 +62,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
IGetDataService service = RetrofitClientInstance.getRetrofitInstance().create(IGetDataService.class);
Call<String> result = service.login(
dbName,
MessagingService.getToken(getContext()),
((EditText) getActivity().findViewById(R.id.user_email_et)).getText().toString()
);

Expand All @@ -72,7 +75,6 @@ public void onResponse(Call<String> call, Response<String> response) {
String token = response.body();

sharedPreferences.edit().putString("token", token).apply();

Toast.makeText(getContext(), "Logged in", Toast.LENGTH_SHORT).show();

Intent intent = new Intent(getContext(), MainActivity.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Call<List<HREmployee>> getDepartmentEmployees(
@POST("login/")
Call<String> login(
@Field("db_name") String db_name,
@Field("fcm_token") String fcm_token,
@Field("user_mail") String db_mail
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.maks.odooprojects.network;

import android.content.Context;
import android.util.Log;

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

public class MessagingService extends FirebaseMessagingService {
@Override
public void onNewToken(String s) {
super.onNewToken(s);
Log.e("newToken", s);
getSharedPreferences("_", MODE_PRIVATE).edit().putString("fb", s).apply();
}

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
}

public static String getToken(Context context) {
return context.getSharedPreferences("_", MODE_PRIVATE).getString("fb", "empty");
}
}
14 changes: 14 additions & 0 deletions app/src/main/res/layout/fragment_create_project_task.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".CreateProjectTaskFragment">

<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />

</FrameLayout>
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'

classpath 'com.google.gms:google-services:4.2.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down

0 comments on commit f81f4f5

Please sign in to comment.