Skip to content

Instantly share code, notes, and snippets.

View zeeshan-mehdi's full-sized avatar
💭
available

zeeshan mehdi zeeshan-mehdi

💭
available
View GitHub Profile
class Conversation {
String id;
// conversation name for example chat with market name
String name;
// Chats messages
String lastMessage;
int lastMessageTime;
Future<void> sendNotification(String body, String title, User user) async {
final data = {
"notification": {"body": "$body", "title": "$title"},
"priority": "high",
"data": {"click_action": "FLUTTER_NOTIFICATION_CLICK", "id": "messages", "status": "done"},
"to": "${user.deviceToken}"
};
final String url = 'https://fcm.googleapis.com/fcm/send';
final client = new http.Client();
final response = await client.post(
addMessage(Conversation _conversation, String text) {
Chat _chat = new Chat(text, DateTime.now().toUtc().millisecondsSinceEpoch, currentUser.value.id);
if (_conversation.id == null) {
_conversation.id = UniqueKey().toString();
createConversation(_conversation);
}
_conversation.lastMessage = text;
_conversation.lastMessageTime = _chat.time;
_conversation.readByUsers = [currentUser.value.id];
_chatRepository.addMessage(_conversation, _chat).then((value) {
@zeeshan-mehdi
zeeshan-mehdi / cityoperator.dart
Created June 1, 2021 15:56
city operator code
import 'dart:convert';
import 'package:dropdownfield/dropdownfield.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:searchable_dropdown/searchable_dropdown.dart';
import 'package:transit/Login.dart';
import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart';
@zeeshan-mehdi
zeeshan-mehdi / lollipop.java
Created July 13, 2018 17:23 — forked from plateaukao/lollipop.java
How to detect foreground process name in Android with Lollipop
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static String getForegroundProcess(Context context) {
String topPackageName = null;
UsageStatsManager usage = (UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE);
long time = System.currentTimeMillis();
List<UsageStats> stats = usage.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, time - 1000*1000, time);
if (stats != null) {
SortedMap<Long, UsageStats> runningTask = new TreeMap<Long,UsageStats>();
for (UsageStats usageStats : stats) {
runningTask.put(usageStats.getLastTimeUsed(), usageStats);