package com.example.layanancomplain;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.CardView;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Toast;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class Menu_engineer extends AppCompatActivity {
String ip="",PESAN="",id_penugasan;
Handler mHandler;
JSONParser jsonParser = new JSONParser();
Vibrator vibrator;
CardView btnProfil, btnPenugasan, btnArsip, btnExit;
String id_user, nama_user;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu_engineer);
ip=jsonParser.getIP();
vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(Menu_engineer.this);
Boolean Registered = sharedPref.getBoolean("Registered", false);
if (!Registered){
finish();
}else {
id_user= sharedPref.getString("id_user", "");
nama_user = sharedPref.getString("nama_user", "");
}
btnProfil=(CardView)findViewById(R.id.btnProfil);
btnProfil.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent i = new Intent(Menu_engineer.this,Profil_user.class);
i.putExtra("pk", id_user);
startActivity(i);
}});
btnPenugasan=(CardView)findViewById(R.id.btnPenugasan);
btnPenugasan.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent i = new Intent(Menu_engineer.this,List_penugasan.class);
startActivity(i);
}});
btnArsip=(CardView)findViewById(R.id.btnArsip);
btnArsip.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent i = new Intent(Menu_engineer.this,List_arsip_penugasan.class);
startActivity(i);
}});
btnExit=(CardView)findViewById(R.id.btnExit);
btnExit.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
keluarYN();
}});
this.mHandler = new Handler();
m_Runnable.run();
}
private final Runnable m_Runnable = new Runnable() {
public void run() {
new Menu_engineer.load().execute();
Menu_engineer.this.mHandler.postDelayed(m_Runnable,5000);
}
};
private void addNotification1() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
vibrator.vibrate(VibrationEffect.createOneShot(1000, VibrationEffect.DEFAULT_AMPLITUDE));
}
Toast.makeText(Menu_engineer.this,"Info "+PESAN,Toast.LENGTH_SHORT).show();
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.phone_icon)
.setContentTitle("Konfirmasi Teknisi Untuk Penugasan ")
.setContentText(PESAN);
Intent notificationIntent = new Intent(this, NorifCustomer.class);//eventList notificationIntent.putExtra("id_penugasan", id_penugasan);
notificationIntent.putExtra("PESAN", PESAN);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(contentIntent);
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(0, builder.build());
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
keluarYN();
return true;
}
return super.onKeyDown(keyCode, event);
}
public void keluar(){
new AlertDialog.Builder(this)
.setTitle("Menutup Aplikasi")
.setMessage("Terimakasih... Anda Telah Menggunakan Aplikasi Ini")
.setNeutralButton("Tutup", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
finish();
}})
.show();
}
public void keluarYN(){
AlertDialog.Builder ad=new AlertDialog.Builder(Menu_engineer.this);
ad.setTitle("Konfirmasi");
ad.setMessage("Apakah benar ingin keluar?");
ad.setPositiveButton("OK",new DialogInterface.OnClickListener(){
@Override public void onClick(DialogInterface dialog, int which) {
keluar();
}});
ad.setNegativeButton("No",new DialogInterface.OnClickListener(){
public void onClick(DialogInterface arg0, int arg1) {
}});
ad.show();
}
int adabaru=0;
class load extends AsyncTask<String, String, String> {
@Override protected void onPreExecute() {
super.onPreExecute();
}
protected String doInBackground(String... args) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("id_user", id_user));
JSONObject json = jsonParser.makeHttpRequest(ip+"penugasanteknisi.php", "GET", params);
Log.d("show: ", json.toString());
try {
adabaru= json.getInt("sukses");
if(adabaru==1){
PESAN= json.getString("PESAN");
id_penugasan= json.getString("id_penugasan");
}
}
catch (JSONException e) {e.printStackTrace();}
return null;
}
protected void onPostExecute(String file_url) {
runOnUiThread(new Runnable() {
public void run() {
if (adabaru==1){
adabaru=0;
addNotification1();
Toast.makeText(Menu_engineer.this,"Ada Info dari Petugas...="+PESAN,Toast.LENGTH_SHORT).show();
}
}
});}
}
}
<?php
require_once"konmysqli.php";
$respon = array();
if (isset($_GET["id_user"])) {
$id_user = $_GET['id_user'];
$sql="SELECT * FROM `$tbpenugasan` WHERE `$tbpenugasan`.`id_user` =
'$id_user' and `$tbpenugasan`.`notif_teknisi`='0'";
$jum=getJum($conn,$sql);
if ($jum>0) {
$d=getField($conn,$sql);
$record = array();
$id_penugasan = $d["id_penugasan"];
$pesanketeknisi= $d["pesan"];
$id_user = $d["id_user"];
$status = $d["status"];
$id_complain= $d["id_complain"];
$namateknisi=getUserM($conn,$id_user);
$pesan= $d["pesan"];
$respon["pesankecustomer"]="Status $status |Penugasan ke Teknisi $namateknisi ($id_user)";
$respon["PESAN"]="$pesan (NO Complain $id_complain)";
$respon["id_penugasan"]=$id_penugasan;
$respon["pesan"] =$pesan;
$respon["sukses"] = 1;
$sqlm="update `$tbpenugasan` set `notif_teknisi`='1' WHERE `id_penugasan` = '$id_penugasan'";
//processM($conn,$sqlm);
$respon["pesan"] = "$jum record";
echo json_encode($respon);
} else {
$respon["sukses"] = 0;
$respon["pesan"] = "0 record";
echo json_encode($respon);
}
} else {
$respon["sukses"] = 0;
$respon["pesan"] = "? lengkapi data";
echo json_encode($respon);
}
?>
<?php
function getJum($conn,$sql){
$rs=$conn->query($sql);
$jum= $rs->num_rows;
$rs->free();
return $jum;
}
function getField($conn,$sql){
$rs=$conn->query($sql);
$rs->data_seek(0);
$d= $rs->fetch_assoc();
$rs->free();
return $d;
}
?>
Tidak ada komentar:
Posting Komentar