package com.merosee.bustrack.parent;


import anywheresoftware.b4a.B4AMenuItem;
import android.app.Activity;
import android.os.Bundle;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BALayout;
import anywheresoftware.b4a.B4AActivity;
import anywheresoftware.b4a.ObjectWrapper;
import anywheresoftware.b4a.objects.ActivityWrapper;
import java.lang.reflect.InvocationTargetException;
import anywheresoftware.b4a.B4AUncaughtException;
import anywheresoftware.b4a.debug.*;
import java.lang.ref.WeakReference;

public class main extends Activity implements B4AActivity{
	public static main mostCurrent;
	static boolean afterFirstLayout;
	static boolean isFirst = true;
    private static boolean processGlobalsRun = false;
	BALayout layout;
	public static BA processBA;
	BA activityBA;
    ActivityWrapper _activity;
    java.util.ArrayList<B4AMenuItem> menuItems;
	public static final boolean fullScreen = false;
	public static final boolean includeTitle = true;
    public static WeakReference<Activity> previousOne;
    public static boolean dontPause;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        mostCurrent = this;
		if (processBA == null) {
			processBA = new BA(this.getApplicationContext(), null, null, "com.merosee.bustrack.parent", "com.merosee.bustrack.parent.main");
			processBA.loadHtSubs(this.getClass());
	        float deviceScale = getApplicationContext().getResources().getDisplayMetrics().density;
	        BALayout.setDeviceScale(deviceScale);
            
		}
		else if (previousOne != null) {
			Activity p = previousOne.get();
			if (p != null && p != this) {
                BA.LogInfo("Killing previous instance (main).");
				p.finish();
			}
		}
        processBA.setActivityPaused(true);
        processBA.runHook("oncreate", this, null);
		if (!includeTitle) {
        	this.getWindow().requestFeature(android.view.Window.FEATURE_NO_TITLE);
        }
        if (fullScreen) {
        	getWindow().setFlags(android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN,   
        			android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
		
        processBA.sharedProcessBA.activityBA = null;
		layout = new BALayout(this);
		setContentView(layout);
		afterFirstLayout = false;
        WaitForLayout wl = new WaitForLayout();
        if (anywheresoftware.b4a.objects.ServiceHelper.StarterHelper.startFromActivity(this, processBA, wl, false))
		    BA.handler.postDelayed(wl, 5);

	}
	static class WaitForLayout implements Runnable {
		public void run() {
			if (afterFirstLayout)
				return;
			if (mostCurrent == null)
				return;
            
			if (mostCurrent.layout.getWidth() == 0) {
				BA.handler.postDelayed(this, 5);
				return;
			}
			mostCurrent.layout.getLayoutParams().height = mostCurrent.layout.getHeight();
			mostCurrent.layout.getLayoutParams().width = mostCurrent.layout.getWidth();
			afterFirstLayout = true;
			mostCurrent.afterFirstLayout();
		}
	}
	private void afterFirstLayout() {
        if (this != mostCurrent)
			return;
		activityBA = new BA(this, layout, processBA, "com.merosee.bustrack.parent", "com.merosee.bustrack.parent.main");
        
        processBA.sharedProcessBA.activityBA = new java.lang.ref.WeakReference<BA>(activityBA);
        anywheresoftware.b4a.objects.ViewWrapper.lastId = 0;
        _activity = new ActivityWrapper(activityBA, "activity");
        anywheresoftware.b4a.Msgbox.isDismissing = false;
        if (BA.isShellModeRuntimeCheck(processBA)) {
			if (isFirst)
				processBA.raiseEvent2(null, true, "SHELL", false);
			processBA.raiseEvent2(null, true, "CREATE", true, "com.merosee.bustrack.parent.main", processBA, activityBA, _activity, anywheresoftware.b4a.keywords.Common.Density, mostCurrent);
			_activity.reinitializeForShell(activityBA, "activity");
		}
        initializeProcessGlobals();		
        initializeGlobals();
        
        BA.LogInfo("** Activity (main) Create " + (isFirst ? "(first time)" : "") + " **");
        processBA.raiseEvent2(null, true, "activity_create", false, isFirst);
		isFirst = false;
		if (this != mostCurrent)
			return;
        processBA.setActivityPaused(false);
        BA.LogInfo("** Activity (main) Resume **");
        processBA.raiseEvent(null, "activity_resume");
        if (android.os.Build.VERSION.SDK_INT >= 11) {
			try {
				android.app.Activity.class.getMethod("invalidateOptionsMenu").invoke(this,(Object[]) null);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	}
	public void addMenuItem(B4AMenuItem item) {
		if (menuItems == null)
			menuItems = new java.util.ArrayList<B4AMenuItem>();
		menuItems.add(item);
	}
	@Override
	public boolean onCreateOptionsMenu(android.view.Menu menu) {
		super.onCreateOptionsMenu(menu);
        try {
            if (processBA.subExists("activity_actionbarhomeclick")) {
                Class.forName("android.app.ActionBar").getMethod("setHomeButtonEnabled", boolean.class).invoke(
                    getClass().getMethod("getActionBar").invoke(this), true);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (processBA.runHook("oncreateoptionsmenu", this, new Object[] {menu}))
            return true;
		if (menuItems == null)
			return false;
		for (B4AMenuItem bmi : menuItems) {
			android.view.MenuItem mi = menu.add(bmi.title);
			if (bmi.drawable != null)
				mi.setIcon(bmi.drawable);
            if (android.os.Build.VERSION.SDK_INT >= 11) {
				try {
                    if (bmi.addToBar) {
				        android.view.MenuItem.class.getMethod("setShowAsAction", int.class).invoke(mi, 1);
                    }
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			mi.setOnMenuItemClickListener(new B4AMenuItemsClickListener(bmi.eventName.toLowerCase(BA.cul)));
		}
        
		return true;
	}   
 @Override
 public boolean onOptionsItemSelected(android.view.MenuItem item) {
    if (item.getItemId() == 16908332) {
        processBA.raiseEvent(null, "activity_actionbarhomeclick");
        return true;
    }
    else
        return super.onOptionsItemSelected(item); 
}
@Override
 public boolean onPrepareOptionsMenu(android.view.Menu menu) {
    super.onPrepareOptionsMenu(menu);
    processBA.runHook("onprepareoptionsmenu", this, new Object[] {menu});
    return true;
    
 }
 protected void onStart() {
    super.onStart();
    processBA.runHook("onstart", this, null);
}
 protected void onStop() {
    super.onStop();
    processBA.runHook("onstop", this, null);
}
    public void onWindowFocusChanged(boolean hasFocus) {
       super.onWindowFocusChanged(hasFocus);
       if (processBA.subExists("activity_windowfocuschanged"))
           processBA.raiseEvent2(null, true, "activity_windowfocuschanged", false, hasFocus);
    }
	private class B4AMenuItemsClickListener implements android.view.MenuItem.OnMenuItemClickListener {
		private final String eventName;
		public B4AMenuItemsClickListener(String eventName) {
			this.eventName = eventName;
		}
		public boolean onMenuItemClick(android.view.MenuItem item) {
			processBA.raiseEventFromUI(item.getTitle(), eventName + "_click");
			return true;
		}
	}
    public static Class<?> getObject() {
		return main.class;
	}
    private Boolean onKeySubExist = null;
    private Boolean onKeyUpSubExist = null;
	@Override
	public boolean onKeyDown(int keyCode, android.view.KeyEvent event) {
        if (processBA.runHook("onkeydown", this, new Object[] {keyCode, event}))
            return true;
		if (onKeySubExist == null)
			onKeySubExist = processBA.subExists("activity_keypress");
		if (onKeySubExist) {
			if (keyCode == anywheresoftware.b4a.keywords.constants.KeyCodes.KEYCODE_BACK &&
					android.os.Build.VERSION.SDK_INT >= 18) {
				HandleKeyDelayed hk = new HandleKeyDelayed();
				hk.kc = keyCode;
				BA.handler.post(hk);
				return true;
			}
			else {
				boolean res = new HandleKeyDelayed().runDirectly(keyCode);
				if (res)
					return true;
			}
		}
		return super.onKeyDown(keyCode, event);
	}
	private class HandleKeyDelayed implements Runnable {
		int kc;
		public void run() {
			runDirectly(kc);
		}
		public boolean runDirectly(int keyCode) {
			Boolean res =  (Boolean)processBA.raiseEvent2(_activity, false, "activity_keypress", false, keyCode);
			if (res == null || res == true) {
                return true;
            }
            else if (keyCode == anywheresoftware.b4a.keywords.constants.KeyCodes.KEYCODE_BACK) {
				finish();
				return true;
			}
            return false;
		}
		
	}
    @Override
	public boolean onKeyUp(int keyCode, android.view.KeyEvent event) {
        if (processBA.runHook("onkeyup", this, new Object[] {keyCode, event}))
            return true;
		if (onKeyUpSubExist == null)
			onKeyUpSubExist = processBA.subExists("activity_keyup");
		if (onKeyUpSubExist) {
			Boolean res =  (Boolean)processBA.raiseEvent2(_activity, false, "activity_keyup", false, keyCode);
			if (res == null || res == true)
				return true;
		}
		return super.onKeyUp(keyCode, event);
	}
	@Override
	public void onNewIntent(android.content.Intent intent) {
        super.onNewIntent(intent);
		this.setIntent(intent);
        processBA.runHook("onnewintent", this, new Object[] {intent});
	}
    @Override 
	public void onPause() {
		super.onPause();
        if (_activity == null)
            return;
        if (this != mostCurrent)
			return;
		anywheresoftware.b4a.Msgbox.dismiss(true);
        if (!dontPause)
            BA.LogInfo("** Activity (main) Pause, UserClosed = " + activityBA.activity.isFinishing() + " **");
        else
            BA.LogInfo("** Activity (main) Pause event (activity is not paused). **");
        if (mostCurrent != null)
            processBA.raiseEvent2(_activity, true, "activity_pause", false, activityBA.activity.isFinishing());		
        if (!dontPause) {
            processBA.setActivityPaused(true);
            mostCurrent = null;
        }

        if (!activityBA.activity.isFinishing())
			previousOne = new WeakReference<Activity>(this);
        anywheresoftware.b4a.Msgbox.isDismissing = false;
        processBA.runHook("onpause", this, null);
	}

	@Override
	public void onDestroy() {
        super.onDestroy();
		previousOne = null;
        processBA.runHook("ondestroy", this, null);
	}
    @Override 
	public void onResume() {
		super.onResume();
        mostCurrent = this;
        anywheresoftware.b4a.Msgbox.isDismissing = false;
        if (activityBA != null) { //will be null during activity create (which waits for AfterLayout).
        	ResumeMessage rm = new ResumeMessage(mostCurrent);
        	BA.handler.post(rm);
        }
        processBA.runHook("onresume", this, null);
	}
    private static class ResumeMessage implements Runnable {
    	private final WeakReference<Activity> activity;
    	public ResumeMessage(Activity activity) {
    		this.activity = new WeakReference<Activity>(activity);
    	}
		public void run() {
            main mc = mostCurrent;
			if (mc == null || mc != activity.get())
				return;
			processBA.setActivityPaused(false);
            BA.LogInfo("** Activity (main) Resume **");
            if (mc != mostCurrent)
                return;
		    processBA.raiseEvent(mc._activity, "activity_resume", (Object[])null);
		}
    }
	@Override
	protected void onActivityResult(int requestCode, int resultCode,
	      android.content.Intent data) {
		processBA.onActivityResult(requestCode, resultCode, data);
        processBA.runHook("onactivityresult", this, new Object[] {requestCode, resultCode});
	}
	private static void initializeGlobals() {
		processBA.raiseEvent2(null, true, "globals", false, (Object[])null);
	}
    public void onRequestPermissionsResult(int requestCode,
        String permissions[], int[] grantResults) {
        for (int i = 0;i < permissions.length;i++) {
            Object[] o = new Object[] {permissions[i], grantResults[i] == 0};
            processBA.raiseEventFromDifferentThread(null,null, 0, "activity_permissionresult", true, o);
        }
            
    }

public anywheresoftware.b4a.keywords.Common __c = null;
public anywheresoftware.b4a.objects.PanelWrapper _pnllogin = null;
public anywheresoftware.b4a.objects.EditTextWrapper _txtphone = null;
public anywheresoftware.b4a.objects.ButtonWrapper _btnlogin = null;
public anywheresoftware.b4a.objects.PanelWrapper _pnlstudents = null;
public anywheresoftware.b4a.objects.ListViewWrapper _lststudents = null;
public anywheresoftware.b4a.objects.ButtonWrapper _btnlogoutparent = null;
public anywheresoftware.b4a.objects.LabelWrapper _lbltokenstatus = null;
public anywheresoftware.b4a.objects.collections.List _currentstudents = null;
public anywheresoftware.b4a.objects.RuntimePermissions _rp = null;
public com.merosee.bustrack.parent.starter _starter = null;
public com.merosee.bustrack.parent.mapactivity _mapactivity = null;
public com.merosee.bustrack.parent.apimodule _apimodule = null;
public com.merosee.bustrack.parent.firebasemessaging _firebasemessaging = null;
public com.merosee.bustrack.parent.httputils2service _httputils2service = null;

public static boolean isAnyActivityVisible() {
    boolean vis = false;
vis = vis | (main.mostCurrent != null);
vis = vis | (mapactivity.mostCurrent != null);
return vis;}
public static String  _activity_create(boolean _firsttime) throws Exception{
anywheresoftware.b4a.objects.FirebaseAnalyticsWrapper _analytics = null;
 //BA.debugLineNum = 34;BA.debugLine="Sub Activity_Create(FirstTime As Boolean)";
 //BA.debugLineNum = 35;BA.debugLine="Activity.Title = \"BusTrack Parent\"";
mostCurrent._activity.setTitle(BA.ObjectToCharSequence("BusTrack Parent"));
 //BA.debugLineNum = 38;BA.debugLine="InitializeUI";
_initializeui();
 //BA.debugLineNum = 40;BA.debugLine="CheckLoginState";
_checkloginstate();
 //BA.debugLineNum = 43;BA.debugLine="Dim analytics As FirebaseAnalytics";
_analytics = new anywheresoftware.b4a.objects.FirebaseAnalyticsWrapper();
 //BA.debugLineNum = 44;BA.debugLine="analytics.Initialize";
_analytics.Initialize();
 //BA.debugLineNum = 45;BA.debugLine="Log(\"Firebase Nudge Sent\")";
anywheresoftware.b4a.keywords.Common.LogImpl("3131083","Firebase Nudge Sent",0);
 //BA.debugLineNum = 48;BA.debugLine="CheckNotificationPermission";
_checknotificationpermission();
 //BA.debugLineNum = 51;BA.debugLine="Log(\"--- APP DIAGNOSTICS ---\")";
anywheresoftware.b4a.keywords.Common.LogImpl("3131089","--- APP DIAGNOSTICS ---",0);
 //BA.debugLineNum = 52;BA.debugLine="Log(\"Package: \" & Application.PackageName)";
anywheresoftware.b4a.keywords.Common.LogImpl("3131090","Package: "+anywheresoftware.b4a.keywords.Common.Application.getPackageName(),0);
 //BA.debugLineNum = 53;BA.debugLine="Log(\"-----------------------\")";
anywheresoftware.b4a.keywords.Common.LogImpl("3131091","-----------------------",0);
 //BA.debugLineNum = 54;BA.debugLine="End Sub";
return "";
}
public static String  _activity_resume() throws Exception{
 //BA.debugLineNum = 122;BA.debugLine="Sub Activity_Resume";
 //BA.debugLineNum = 123;BA.debugLine="End Sub";
return "";
}
public static String  _btnlogin_click() throws Exception{
String _phone = "";
anywheresoftware.b4a.objects.collections.Map _data = null;
anywheresoftware.b4a.objects.collections.JSONParser.JSONGenerator _json = null;
com.merosee.bustrack.parent.httpjob _job = null;
 //BA.debugLineNum = 183;BA.debugLine="Sub btnLogin_Click";
 //BA.debugLineNum = 184;BA.debugLine="Dim phone As String = txtPhone.Text.Trim";
_phone = mostCurrent._txtphone.getText().trim();
 //BA.debugLineNum = 185;BA.debugLine="Log(\"Login attempt with phone: \" & phone)";
anywheresoftware.b4a.keywords.Common.LogImpl("3655362","Login attempt with phone: "+_phone,0);
 //BA.debugLineNum = 186;BA.debugLine="If phone = \"\" Then";
if ((_phone).equals("")) { 
 //BA.debugLineNum = 187;BA.debugLine="ToastMessageShow(\"Please enter your phone number";
anywheresoftware.b4a.keywords.Common.ToastMessageShow(BA.ObjectToCharSequence("Please enter your phone number"),anywheresoftware.b4a.keywords.Common.True);
 //BA.debugLineNum = 188;BA.debugLine="Return";
if (true) return "";
 };
 //BA.debugLineNum = 190;BA.debugLine="File.WriteString(File.DirInternal, \"parent_phone.";
anywheresoftware.b4a.keywords.Common.File.WriteString(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"parent_phone.txt",_phone);
 //BA.debugLineNum = 192;BA.debugLine="Dim data As Map";
_data = new anywheresoftware.b4a.objects.collections.Map();
 //BA.debugLineNum = 193;BA.debugLine="data.Initialize";
_data.Initialize();
 //BA.debugLineNum = 194;BA.debugLine="data.Put(\"phone\", phone)";
_data.Put((Object)("phone"),(Object)(_phone));
 //BA.debugLineNum = 196;BA.debugLine="Dim json As JSONGenerator";
_json = new anywheresoftware.b4a.objects.collections.JSONParser.JSONGenerator();
 //BA.debugLineNum = 197;BA.debugLine="json.Initialize(data)";
_json.Initialize(_data);
 //BA.debugLineNum = 199;BA.debugLine="Dim job As HttpJob";
_job = new com.merosee.bustrack.parent.httpjob();
 //BA.debugLineNum = 200;BA.debugLine="job.Initialize(\"parent_login\", Me)";
_job._initialize /*String*/ (processBA,"parent_login",main.getObject());
 //BA.debugLineNum = 201;BA.debugLine="job.PostString(APIModule.ServerURL & \"/parent_log";
_job._poststring /*String*/ (mostCurrent._apimodule._serverurl /*String*/ +"/parent_login.php",_json.ToString());
 //BA.debugLineNum = 202;BA.debugLine="job.GetRequest.SetHeader(\"Content-Type\", \"applica";
_job._getrequest /*anywheresoftware.b4h.okhttp.OkHttpClientWrapper.OkHttpRequest*/ ().SetHeader("Content-Type","application/json");
 //BA.debugLineNum = 203;BA.debugLine="End Sub";
return "";
}
public static String  _btnlogoutparent_click() throws Exception{
 //BA.debugLineNum = 250;BA.debugLine="Sub btnLogoutParent_Click";
 //BA.debugLineNum = 251;BA.debugLine="File.Delete(File.DirInternal, \"parent_token.txt\")";
anywheresoftware.b4a.keywords.Common.File.Delete(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"parent_token.txt");
 //BA.debugLineNum = 252;BA.debugLine="File.Delete(File.DirInternal, \"students.json\")";
anywheresoftware.b4a.keywords.Common.File.Delete(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"students.json");
 //BA.debugLineNum = 253;BA.debugLine="File.Delete(File.DirInternal, \"parent_phone.txt\")";
anywheresoftware.b4a.keywords.Common.File.Delete(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"parent_phone.txt");
 //BA.debugLineNum = 254;BA.debugLine="ShowLogin";
_showlogin();
 //BA.debugLineNum = 255;BA.debugLine="End Sub";
return "";
}
public static String  _checkloginstate() throws Exception{
 //BA.debugLineNum = 125;BA.debugLine="Sub CheckLoginState";
 //BA.debugLineNum = 126;BA.debugLine="If APIModule.GetToken = \"\" Or APIModule.GetStuden";
if ((mostCurrent._apimodule._gettoken /*String*/ (mostCurrent.activityBA)).equals("") || (mostCurrent._apimodule._getstudents /*String*/ (mostCurrent.activityBA)).equals("")) { 
 //BA.debugLineNum = 127;BA.debugLine="ShowLogin";
_showlogin();
 }else {
 //BA.debugLineNum = 129;BA.debugLine="ShowStudentSelection";
_showstudentselection();
 };
 //BA.debugLineNum = 131;BA.debugLine="End Sub";
return "";
}
public static void  _checknotificationpermission() throws Exception{
ResumableSub_CheckNotificationPermission rsub = new ResumableSub_CheckNotificationPermission(null);
rsub.resume(processBA, null);
}
public static class ResumableSub_CheckNotificationPermission extends BA.ResumableSub {
public ResumableSub_CheckNotificationPermission(com.merosee.bustrack.parent.main parent) {
this.parent = parent;
}
com.merosee.bustrack.parent.main parent;
anywheresoftware.b4a.phone.Phone _p = null;
String _permission = "";
boolean _result = false;

@Override
public void resume(BA ba, Object[] result) throws Exception{

    while (true) {
        switch (state) {
            case -1:
return;

case 0:
//C
this.state = 1;
 //BA.debugLineNum = 57;BA.debugLine="Dim p As Phone";
_p = new anywheresoftware.b4a.phone.Phone();
 //BA.debugLineNum = 58;BA.debugLine="If p.SdkVersion >= 33 Then";
if (true) break;

case 1:
//if
this.state = 8;
if (_p.getSdkVersion()>=33) { 
this.state = 3;
}if (true) break;

case 3:
//C
this.state = 4;
 //BA.debugLineNum = 59;BA.debugLine="rp.CheckAndRequest(\"android.permission.POST_NOTI";
parent.mostCurrent._rp.CheckAndRequest(processBA,"android.permission.POST_NOTIFICATIONS");
 //BA.debugLineNum = 60;BA.debugLine="Wait For Activity_PermissionResult (Permission A";
anywheresoftware.b4a.keywords.Common.WaitFor("activity_permissionresult", processBA, this, null);
this.state = 9;
return;
case 9:
//C
this.state = 4;
_permission = (String) result[0];
_result = (Boolean) result[1];
;
 //BA.debugLineNum = 61;BA.debugLine="If Result = False Then";
if (true) break;

case 4:
//if
this.state = 7;
if (_result==anywheresoftware.b4a.keywords.Common.False) { 
this.state = 6;
}if (true) break;

case 6:
//C
this.state = 7;
 //BA.debugLineNum = 62;BA.debugLine="ToastMessageShow(\"Notifications are disabled. Y";
anywheresoftware.b4a.keywords.Common.ToastMessageShow(BA.ObjectToCharSequence("Notifications are disabled. You won't receive bus alerts."),anywheresoftware.b4a.keywords.Common.True);
 if (true) break;

case 7:
//C
this.state = 8;
;
 if (true) break;

case 8:
//C
this.state = -1;
;
 //BA.debugLineNum = 65;BA.debugLine="End Sub";
if (true) break;

            }
        }
    }
}
public static void  _activity_permissionresult(String _permission,boolean _result) throws Exception{
}
public static String  _globals() throws Exception{
 //BA.debugLineNum = 18;BA.debugLine="Sub Globals";
 //BA.debugLineNum = 20;BA.debugLine="Private pnlLogin As Panel";
mostCurrent._pnllogin = new anywheresoftware.b4a.objects.PanelWrapper();
 //BA.debugLineNum = 21;BA.debugLine="Private txtPhone As EditText";
mostCurrent._txtphone = new anywheresoftware.b4a.objects.EditTextWrapper();
 //BA.debugLineNum = 22;BA.debugLine="Private btnLogin As Button";
mostCurrent._btnlogin = new anywheresoftware.b4a.objects.ButtonWrapper();
 //BA.debugLineNum = 25;BA.debugLine="Private pnlStudents As Panel";
mostCurrent._pnlstudents = new anywheresoftware.b4a.objects.PanelWrapper();
 //BA.debugLineNum = 26;BA.debugLine="Private lstStudents As ListView";
mostCurrent._lststudents = new anywheresoftware.b4a.objects.ListViewWrapper();
 //BA.debugLineNum = 27;BA.debugLine="Private btnLogoutParent As Button";
mostCurrent._btnlogoutparent = new anywheresoftware.b4a.objects.ButtonWrapper();
 //BA.debugLineNum = 29;BA.debugLine="Private lblTokenStatus As Label";
mostCurrent._lbltokenstatus = new anywheresoftware.b4a.objects.LabelWrapper();
 //BA.debugLineNum = 30;BA.debugLine="Private CurrentStudents As List";
mostCurrent._currentstudents = new anywheresoftware.b4a.objects.collections.List();
 //BA.debugLineNum = 31;BA.debugLine="Private rp As RuntimePermissions";
mostCurrent._rp = new anywheresoftware.b4a.objects.RuntimePermissions();
 //BA.debugLineNum = 32;BA.debugLine="End Sub";
return "";
}
public static String  _initializeui() throws Exception{
anywheresoftware.b4a.objects.LabelWrapper _lbltitle = null;
anywheresoftware.b4a.objects.LabelWrapper _lblstudents = null;
 //BA.debugLineNum = 67;BA.debugLine="Sub InitializeUI";
 //BA.debugLineNum = 69;BA.debugLine="pnlLogin.Initialize(\"\")";
mostCurrent._pnllogin.Initialize(mostCurrent.activityBA,"");
 //BA.debugLineNum = 70;BA.debugLine="Activity.AddView(pnlLogin, 0, 0, 100%x, 100%y)";
mostCurrent._activity.AddView((android.view.View)(mostCurrent._pnllogin.getObject()),(int) (0),(int) (0),anywheresoftware.b4a.keywords.Common.PerXToCurrent((float) (100),mostCurrent.activityBA),anywheresoftware.b4a.keywords.Common.PerYToCurrent((float) (100),mostCurrent.activityBA));
 //BA.debugLineNum = 71;BA.debugLine="pnlLogin.Color = Colors.White";
mostCurrent._pnllogin.setColor(anywheresoftware.b4a.keywords.Common.Colors.White);
 //BA.debugLineNum = 73;BA.debugLine="Dim lblTitle As Label";
_lbltitle = new anywheresoftware.b4a.objects.LabelWrapper();
 //BA.debugLineNum = 74;BA.debugLine="lblTitle.Initialize(\"\")";
_lbltitle.Initialize(mostCurrent.activityBA,"");
 //BA.debugLineNum = 75;BA.debugLine="lblTitle.Text = \"Parent Login\"";
_lbltitle.setText(BA.ObjectToCharSequence("Parent Login"));
 //BA.debugLineNum = 76;BA.debugLine="lblTitle.TextSize = 24";
_lbltitle.setTextSize((float) (24));
 //BA.debugLineNum = 77;BA.debugLine="lblTitle.Gravity = Gravity.CENTER";
_lbltitle.setGravity(anywheresoftware.b4a.keywords.Common.Gravity.CENTER);
 //BA.debugLineNum = 78;BA.debugLine="pnlLogin.AddView(lblTitle, 10%x, 20%y, 80%x, 50di";
mostCurrent._pnllogin.AddView((android.view.View)(_lbltitle.getObject()),anywheresoftware.b4a.keywords.Common.PerXToCurrent((float) (10),mostCurrent.activityBA),anywheresoftware.b4a.keywords.Common.PerYToCurrent((float) (20),mostCurrent.activityBA),anywheresoftware.b4a.keywords.Common.PerXToCurrent((float) (80),mostCurrent.activityBA),anywheresoftware.b4a.keywords.Common.DipToCurrent((int) (50)));
 //BA.debugLineNum = 80;BA.debugLine="txtPhone.Initialize(\"txtPhone\")";
mostCurrent._txtphone.Initialize(mostCurrent.activityBA,"txtPhone");
 //BA.debugLineNum = 81;BA.debugLine="txtPhone.Hint = \"Enter your phone number\"";
mostCurrent._txtphone.setHint("Enter your phone number");
 //BA.debugLineNum = 82;BA.debugLine="txtPhone.InputType = txtPhone.INPUT_TYPE_PHONE";
mostCurrent._txtphone.setInputType(mostCurrent._txtphone.INPUT_TYPE_PHONE);
 //BA.debugLineNum = 83;BA.debugLine="pnlLogin.AddView(txtPhone, 10%x, 35%y, 80%x, 50di";
mostCurrent._pnllogin.AddView((android.view.View)(mostCurrent._txtphone.getObject()),anywheresoftware.b4a.keywords.Common.PerXToCurrent((float) (10),mostCurrent.activityBA),anywheresoftware.b4a.keywords.Common.PerYToCurrent((float) (35),mostCurrent.activityBA),anywheresoftware.b4a.keywords.Common.PerXToCurrent((float) (80),mostCurrent.activityBA),anywheresoftware.b4a.keywords.Common.DipToCurrent((int) (50)));
 //BA.debugLineNum = 85;BA.debugLine="btnLogin.Initialize(\"btnLogin\")";
mostCurrent._btnlogin.Initialize(mostCurrent.activityBA,"btnLogin");
 //BA.debugLineNum = 86;BA.debugLine="btnLogin.Text = \"LOGIN\"";
mostCurrent._btnlogin.setText(BA.ObjectToCharSequence("LOGIN"));
 //BA.debugLineNum = 87;BA.debugLine="pnlLogin.AddView(btnLogin, 10%x, 45%y, 80%x, 50di";
mostCurrent._pnllogin.AddView((android.view.View)(mostCurrent._btnlogin.getObject()),anywheresoftware.b4a.keywords.Common.PerXToCurrent((float) (10),mostCurrent.activityBA),anywheresoftware.b4a.keywords.Common.PerYToCurrent((float) (45),mostCurrent.activityBA),anywheresoftware.b4a.keywords.Common.PerXToCurrent((float) (80),mostCurrent.activityBA),anywheresoftware.b4a.keywords.Common.DipToCurrent((int) (50)));
 //BA.debugLineNum = 90;BA.debugLine="pnlStudents.Initialize(\"\")";
mostCurrent._pnlstudents.Initialize(mostCurrent.activityBA,"");
 //BA.debugLineNum = 91;BA.debugLine="Activity.AddView(pnlStudents, 0, 0, 100%x, 100%y)";
mostCurrent._activity.AddView((android.view.View)(mostCurrent._pnlstudents.getObject()),(int) (0),(int) (0),anywheresoftware.b4a.keywords.Common.PerXToCurrent((float) (100),mostCurrent.activityBA),anywheresoftware.b4a.keywords.Common.PerYToCurrent((float) (100),mostCurrent.activityBA));
 //BA.debugLineNum = 92;BA.debugLine="pnlStudents.Color = Colors.White";
mostCurrent._pnlstudents.setColor(anywheresoftware.b4a.keywords.Common.Colors.White);
 //BA.debugLineNum = 93;BA.debugLine="pnlStudents.Visible = False";
mostCurrent._pnlstudents.setVisible(anywheresoftware.b4a.keywords.Common.False);
 //BA.debugLineNum = 95;BA.debugLine="Dim lblStudents As Label";
_lblstudents = new anywheresoftware.b4a.objects.LabelWrapper();
 //BA.debugLineNum = 96;BA.debugLine="lblStudents.Initialize(\"\")";
_lblstudents.Initialize(mostCurrent.activityBA,"");
 //BA.debugLineNum = 97;BA.debugLine="lblStudents.Text = \"Select Your Child\"";
_lblstudents.setText(BA.ObjectToCharSequence("Select Your Child"));
 //BA.debugLineNum = 98;BA.debugLine="lblStudents.TextSize = 20";
_lblstudents.setTextSize((float) (20));
 //BA.debugLineNum = 99;BA.debugLine="lblStudents.Gravity = Gravity.CENTER";
_lblstudents.setGravity(anywheresoftware.b4a.keywords.Common.Gravity.CENTER);
 //BA.debugLineNum = 100;BA.debugLine="pnlStudents.AddView(lblStudents, 10%x, 10%y, 80%x";
mostCurrent._pnlstudents.AddView((android.view.View)(_lblstudents.getObject()),anywheresoftware.b4a.keywords.Common.PerXToCurrent((float) (10),mostCurrent.activityBA),anywheresoftware.b4a.keywords.Common.PerYToCurrent((float) (10),mostCurrent.activityBA),anywheresoftware.b4a.keywords.Common.PerXToCurrent((float) (80),mostCurrent.activityBA),anywheresoftware.b4a.keywords.Common.DipToCurrent((int) (50)));
 //BA.debugLineNum = 102;BA.debugLine="lstStudents.Initialize(\"lstStudents\")";
mostCurrent._lststudents.Initialize(mostCurrent.activityBA,"lstStudents");
 //BA.debugLineNum = 103;BA.debugLine="lstStudents.SingleLineLayout.Label.TextColor = Co";
mostCurrent._lststudents.getSingleLineLayout().Label.setTextColor(anywheresoftware.b4a.keywords.Common.Colors.Black);
 //BA.debugLineNum = 104;BA.debugLine="lstStudents.SingleLineLayout.Label.TextSize = 16";
mostCurrent._lststudents.getSingleLineLayout().Label.setTextSize((float) (16));
 //BA.debugLineNum = 105;BA.debugLine="lstStudents.SingleLineLayout.ItemHeight = 60dip";
mostCurrent._lststudents.getSingleLineLayout().setItemHeight(anywheresoftware.b4a.keywords.Common.DipToCurrent((int) (60)));
 //BA.debugLineNum = 106;BA.debugLine="pnlStudents.AddView(lstStudents, 5%x, 20%y, 90%x,";
mostCurrent._pnlstudents.AddView((android.view.View)(mostCurrent._lststudents.getObject()),anywheresoftware.b4a.keywords.Common.PerXToCurrent((float) (5),mostCurrent.activityBA),anywheresoftware.b4a.keywords.Common.PerYToCurrent((float) (20),mostCurrent.activityBA),anywheresoftware.b4a.keywords.Common.PerXToCurrent((float) (90),mostCurrent.activityBA),anywheresoftware.b4a.keywords.Common.PerYToCurrent((float) (60),mostCurrent.activityBA));
 //BA.debugLineNum = 109;BA.debugLine="btnLogoutParent.Initialize(\"btnLogoutParent\")";
mostCurrent._btnlogoutparent.Initialize(mostCurrent.activityBA,"btnLogoutParent");
 //BA.debugLineNum = 110;BA.debugLine="btnLogoutParent.Text = \"LOGOUT / CHANGE NUMBER\"";
mostCurrent._btnlogoutparent.setText(BA.ObjectToCharSequence("LOGOUT / CHANGE NUMBER"));
 //BA.debugLineNum = 111;BA.debugLine="btnLogoutParent.TextColor = Colors.Red";
mostCurrent._btnlogoutparent.setTextColor(anywheresoftware.b4a.keywords.Common.Colors.Red);
 //BA.debugLineNum = 112;BA.debugLine="pnlStudents.AddView(btnLogoutParent, 10%x, 85%y,";
mostCurrent._pnlstudents.AddView((android.view.View)(mostCurrent._btnlogoutparent.getObject()),anywheresoftware.b4a.keywords.Common.PerXToCurrent((float) (10),mostCurrent.activityBA),anywheresoftware.b4a.keywords.Common.PerYToCurrent((float) (85),mostCurrent.activityBA),anywheresoftware.b4a.keywords.Common.PerXToCurrent((float) (80),mostCurrent.activityBA),anywheresoftware.b4a.keywords.Common.DipToCurrent((int) (50)));
 //BA.debugLineNum = 114;BA.debugLine="lblTokenStatus.Initialize(\"\")";
mostCurrent._lbltokenstatus.Initialize(mostCurrent.activityBA,"");
 //BA.debugLineNum = 115;BA.debugLine="lblTokenStatus.Text = \"FCM Status: Initializing..";
mostCurrent._lbltokenstatus.setText(BA.ObjectToCharSequence("FCM Status: Initializing..."));
 //BA.debugLineNum = 116;BA.debugLine="lblTokenStatus.TextSize = 10";
mostCurrent._lbltokenstatus.setTextSize((float) (10));
 //BA.debugLineNum = 117;BA.debugLine="lblTokenStatus.TextColor = Colors.LightGray";
mostCurrent._lbltokenstatus.setTextColor(anywheresoftware.b4a.keywords.Common.Colors.LightGray);
 //BA.debugLineNum = 118;BA.debugLine="lblTokenStatus.Gravity = Gravity.CENTER";
mostCurrent._lbltokenstatus.setGravity(anywheresoftware.b4a.keywords.Common.Gravity.CENTER);
 //BA.debugLineNum = 119;BA.debugLine="Activity.AddView(lblTokenStatus, 0, 95%y, 100%x,";
mostCurrent._activity.AddView((android.view.View)(mostCurrent._lbltokenstatus.getObject()),(int) (0),anywheresoftware.b4a.keywords.Common.PerYToCurrent((float) (95),mostCurrent.activityBA),anywheresoftware.b4a.keywords.Common.PerXToCurrent((float) (100),mostCurrent.activityBA),anywheresoftware.b4a.keywords.Common.PerYToCurrent((float) (5),mostCurrent.activityBA));
 //BA.debugLineNum = 120;BA.debugLine="End Sub";
return "";
}
public static String  _jobdone(com.merosee.bustrack.parent.httpjob _job) throws Exception{
anywheresoftware.b4a.objects.collections.JSONParser _parser = null;
anywheresoftware.b4a.objects.collections.Map _root = null;
boolean _success = false;
String _token = "";
anywheresoftware.b4a.objects.collections.List _students = null;
anywheresoftware.b4a.objects.collections.JSONParser.JSONGenerator _gen = null;
String _studentsjson = "";
String _errormsg = "";
 //BA.debugLineNum = 257;BA.debugLine="Sub JobDone(Job As HttpJob)";
 //BA.debugLineNum = 258;BA.debugLine="If Job.Success Then";
if (_job._success /*boolean*/ ) { 
 //BA.debugLineNum = 259;BA.debugLine="If Job.JobName = \"parent_login\" Then";
if ((_job._jobname /*String*/ ).equals("parent_login")) { 
 //BA.debugLineNum = 260;BA.debugLine="Try";
try { //BA.debugLineNum = 261;BA.debugLine="Dim parser As JSONParser";
_parser = new anywheresoftware.b4a.objects.collections.JSONParser();
 //BA.debugLineNum = 262;BA.debugLine="parser.Initialize(Job.GetString)";
_parser.Initialize(_job._getstring /*String*/ ());
 //BA.debugLineNum = 263;BA.debugLine="Dim root As Map = parser.NextObject";
_root = new anywheresoftware.b4a.objects.collections.Map();
_root = _parser.NextObject();
 //BA.debugLineNum = 264;BA.debugLine="Log(\"Server Response: \" & Job.GetString)";
anywheresoftware.b4a.keywords.Common.LogImpl("3917511","Server Response: "+_job._getstring /*String*/ (),0);
 //BA.debugLineNum = 266;BA.debugLine="Dim success As Boolean = root.Get(\"success\")";
_success = BA.ObjectToBoolean(_root.Get((Object)("success")));
 //BA.debugLineNum = 267;BA.debugLine="If success Then";
if (_success) { 
 //BA.debugLineNum = 268;BA.debugLine="Dim token As String = root.Get(\"token\")";
_token = BA.ObjectToString(_root.Get((Object)("token")));
 //BA.debugLineNum = 269;BA.debugLine="APIModule.SaveToken(token)";
mostCurrent._apimodule._savetoken /*String*/ (mostCurrent.activityBA,_token);
 //BA.debugLineNum = 272;BA.debugLine="Dim students As List = root.Get(\"students\")";
_students = new anywheresoftware.b4a.objects.collections.List();
_students = (anywheresoftware.b4a.objects.collections.List) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.collections.List(), (java.util.List)(_root.Get((Object)("students"))));
 //BA.debugLineNum = 273;BA.debugLine="Log(\"Received \" & students.Size & \" students";
anywheresoftware.b4a.keywords.Common.LogImpl("3917520","Received "+BA.NumberToString(_students.getSize())+" students from server",0);
 //BA.debugLineNum = 275;BA.debugLine="Dim gen As JSONGenerator";
_gen = new anywheresoftware.b4a.objects.collections.JSONParser.JSONGenerator();
 //BA.debugLineNum = 276;BA.debugLine="gen.Initialize2(students)";
_gen.Initialize2(_students);
 //BA.debugLineNum = 277;BA.debugLine="Dim studentsJson As String = gen.ToString";
_studentsjson = _gen.ToString();
 //BA.debugLineNum = 278;BA.debugLine="APIModule.SaveStudents(studentsJson)";
mostCurrent._apimodule._savestudents /*String*/ (mostCurrent.activityBA,_studentsjson);
 //BA.debugLineNum = 280;BA.debugLine="ToastMessageShow(\"Login success: \" & students";
anywheresoftware.b4a.keywords.Common.ToastMessageShow(BA.ObjectToCharSequence("Login success: "+BA.NumberToString(_students.getSize())+" students"),anywheresoftware.b4a.keywords.Common.False);
 //BA.debugLineNum = 281;BA.debugLine="ShowStudentSelection";
_showstudentselection();
 }else {
 //BA.debugLineNum = 283;BA.debugLine="Dim errorMsg As String = root.Get(\"error\")";
_errormsg = BA.ObjectToString(_root.Get((Object)("error")));
 //BA.debugLineNum = 284;BA.debugLine="ToastMessageShow(\"Error: \" & errorMsg, True)";
anywheresoftware.b4a.keywords.Common.ToastMessageShow(BA.ObjectToCharSequence("Error: "+_errormsg),anywheresoftware.b4a.keywords.Common.True);
 };
 } 
       catch (Exception e25) {
			processBA.setLastException(e25); //BA.debugLineNum = 287;BA.debugLine="Log(LastException)";
anywheresoftware.b4a.keywords.Common.LogImpl("3917534",BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(mostCurrent.activityBA)),0);
 //BA.debugLineNum = 288;BA.debugLine="ToastMessageShow(\"Login failed\", True)";
anywheresoftware.b4a.keywords.Common.ToastMessageShow(BA.ObjectToCharSequence("Login failed"),anywheresoftware.b4a.keywords.Common.True);
 };
 }else if((_job._jobname /*String*/ ).equals("register_fcm")) { 
 //BA.debugLineNum = 291;BA.debugLine="Log(\"FCM Token registration response: \" & Job.G";
anywheresoftware.b4a.keywords.Common.LogImpl("3917538","FCM Token registration response: "+_job._getstring /*String*/ (),0);
 //BA.debugLineNum = 292;BA.debugLine="Try";
try { //BA.debugLineNum = 293;BA.debugLine="Dim parser As JSONParser";
_parser = new anywheresoftware.b4a.objects.collections.JSONParser();
 //BA.debugLineNum = 294;BA.debugLine="parser.Initialize(Job.GetString)";
_parser.Initialize(_job._getstring /*String*/ ());
 //BA.debugLineNum = 295;BA.debugLine="Dim root As Map = parser.NextObject";
_root = new anywheresoftware.b4a.objects.collections.Map();
_root = _parser.NextObject();
 //BA.debugLineNum = 296;BA.debugLine="If root.Get(\"success\") = True Then";
if ((_root.Get((Object)("success"))).equals((Object)(anywheresoftware.b4a.keywords.Common.True))) { 
 //BA.debugLineNum = 297;BA.debugLine="Log(\"FCM Token registered successfully\")";
anywheresoftware.b4a.keywords.Common.LogImpl("3917544","FCM Token registered successfully",0);
 };
 } 
       catch (Exception e38) {
			processBA.setLastException(e38); //BA.debugLineNum = 300;BA.debugLine="Log(\"FCM registration parse error: \" & LastExc";
anywheresoftware.b4a.keywords.Common.LogImpl("3917547","FCM registration parse error: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(mostCurrent.activityBA)),0);
 };
 };
 }else {
 //BA.debugLineNum = 304;BA.debugLine="ToastMessageShow(\"Network error: \" & Job.ErrorMe";
anywheresoftware.b4a.keywords.Common.ToastMessageShow(BA.ObjectToCharSequence("Network error: "+_job._errormessage /*String*/ ),anywheresoftware.b4a.keywords.Common.True);
 };
 //BA.debugLineNum = 306;BA.debugLine="Job.Release";
_job._release /*String*/ ();
 //BA.debugLineNum = 307;BA.debugLine="End Sub";
return "";
}
public static String  _loadstudents() throws Exception{
String _studentsjson = "";
anywheresoftware.b4a.objects.collections.JSONParser _parser = null;
anywheresoftware.b4a.objects.collections.Map _student = null;
String _sname = "";
String _sbus = "";
 //BA.debugLineNum = 205;BA.debugLine="Sub LoadStudents";
 //BA.debugLineNum = 206;BA.debugLine="Dim studentsJson As String = APIModule.GetStudent";
_studentsjson = mostCurrent._apimodule._getstudents /*String*/ (mostCurrent.activityBA);
 //BA.debugLineNum = 207;BA.debugLine="Log(\"Loading students from storage: \" & studentsJ";
anywheresoftware.b4a.keywords.Common.LogImpl("3720898","Loading students from storage: "+_studentsjson,0);
 //BA.debugLineNum = 208;BA.debugLine="If studentsJson <> \"\" Then";
if ((_studentsjson).equals("") == false) { 
 //BA.debugLineNum = 209;BA.debugLine="Try";
try { //BA.debugLineNum = 210;BA.debugLine="Dim parser As JSONParser";
_parser = new anywheresoftware.b4a.objects.collections.JSONParser();
 //BA.debugLineNum = 211;BA.debugLine="parser.Initialize(studentsJson)";
_parser.Initialize(_studentsjson);
 //BA.debugLineNum = 212;BA.debugLine="CurrentStudents = parser.NextArray";
mostCurrent._currentstudents = _parser.NextArray();
 //BA.debugLineNum = 213;BA.debugLine="Log(\"Students count: \" & CurrentStudents.Size)";
anywheresoftware.b4a.keywords.Common.LogImpl("3720904","Students count: "+BA.NumberToString(mostCurrent._currentstudents.getSize()),0);
 //BA.debugLineNum = 215;BA.debugLine="lstStudents.Clear";
mostCurrent._lststudents.Clear();
 //BA.debugLineNum = 216;BA.debugLine="For Each student As Map In CurrentStudents";
_student = new anywheresoftware.b4a.objects.collections.Map();
{
final anywheresoftware.b4a.BA.IterableList group10 = mostCurrent._currentstudents;
final int groupLen10 = group10.getSize()
;int index10 = 0;
;
for (; index10 < groupLen10;index10++){
_student = (anywheresoftware.b4a.objects.collections.Map) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.collections.Map(), (java.util.Map)(group10.Get(index10)));
 //BA.debugLineNum = 217;BA.debugLine="Dim sName As String = student.Get(\"name\")";
_sname = BA.ObjectToString(_student.Get((Object)("name")));
 //BA.debugLineNum = 218;BA.debugLine="Dim sBus As String = student.GetDefault(\"bus_n";
_sbus = BA.ObjectToString(_student.GetDefault((Object)("bus_number"),(Object)("Not Assigned")));
 //BA.debugLineNum = 219;BA.debugLine="Log(\"Adding student: \" & sName)";
anywheresoftware.b4a.keywords.Common.LogImpl("3720910","Adding student: "+_sname,0);
 //BA.debugLineNum = 220;BA.debugLine="lstStudents.AddSingleLine(sName & \" - Bus: \" &";
mostCurrent._lststudents.AddSingleLine(BA.ObjectToCharSequence(_sname+" - Bus: "+_sbus));
 }
};
 //BA.debugLineNum = 223;BA.debugLine="If CurrentStudents.Size = 0 Then";
if (mostCurrent._currentstudents.getSize()==0) { 
 //BA.debugLineNum = 224;BA.debugLine="ToastMessageShow(\"No students found\", True)";
anywheresoftware.b4a.keywords.Common.ToastMessageShow(BA.ObjectToCharSequence("No students found"),anywheresoftware.b4a.keywords.Common.True);
 };
 } 
       catch (Exception e20) {
			processBA.setLastException(e20); //BA.debugLineNum = 227;BA.debugLine="Log(\"Error loading students: \" & LastException)";
anywheresoftware.b4a.keywords.Common.LogImpl("3720918","Error loading students: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(mostCurrent.activityBA)),0);
 };
 };
 //BA.debugLineNum = 230;BA.debugLine="End Sub";
return "";
}
public static String  _lststudents_itemclick(int _position,Object _value) throws Exception{
anywheresoftware.b4a.objects.collections.Map _selectedstudent = null;
Object _busidobj = null;
anywheresoftware.b4a.objects.collections.JSONParser.JSONGenerator _gen = null;
 //BA.debugLineNum = 234;BA.debugLine="Sub lstStudents_ItemClick (Position As Int, Value";
 //BA.debugLineNum = 235;BA.debugLine="Dim selectedStudent As Map = CurrentStudents.Get(";
_selectedstudent = new anywheresoftware.b4a.objects.collections.Map();
_selectedstudent = (anywheresoftware.b4a.objects.collections.Map) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.collections.Map(), (java.util.Map)(mostCurrent._currentstudents.Get(_position)));
 //BA.debugLineNum = 237;BA.debugLine="Dim busIdObj As Object = selectedStudent.GetDefau";
_busidobj = _selectedstudent.GetDefault((Object)("bus_id"),(Object)(0));
 //BA.debugLineNum = 238;BA.debugLine="If 0 = busIdObj Then";
if (0==(double)(BA.ObjectToNumber(_busidobj))) { 
 //BA.debugLineNum = 239;BA.debugLine="ToastMessageShow(\"No bus assigned to this studen";
anywheresoftware.b4a.keywords.Common.ToastMessageShow(BA.ObjectToCharSequence("No bus assigned to this student"),anywheresoftware.b4a.keywords.Common.True);
 //BA.debugLineNum = 240;BA.debugLine="Return";
if (true) return "";
 };
 //BA.debugLineNum = 244;BA.debugLine="Dim gen As JSONGenerator";
_gen = new anywheresoftware.b4a.objects.collections.JSONParser.JSONGenerator();
 //BA.debugLineNum = 245;BA.debugLine="gen.Initialize(selectedStudent)";
_gen.Initialize(_selectedstudent);
 //BA.debugLineNum = 246;BA.debugLine="File.WriteString(File.DirInternal, \"selected_stud";
anywheresoftware.b4a.keywords.Common.File.WriteString(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"selected_student.json",_gen.ToString());
 //BA.debugLineNum = 247;BA.debugLine="StartActivity(MapActivity)";
anywheresoftware.b4a.keywords.Common.StartActivity(processBA,(Object)(mostCurrent._mapactivity.getObject()));
 //BA.debugLineNum = 248;BA.debugLine="End Sub";
return "";
}

public static void initializeProcessGlobals() {
    
    if (main.processGlobalsRun == false) {
	    main.processGlobalsRun = true;
		try {
		        main._process_globals();
starter._process_globals();
mapactivity._process_globals();
apimodule._process_globals();
firebasemessaging._process_globals();
httputils2service._process_globals();
		
        } catch (Exception e) {
			throw new RuntimeException(e);
		}
    }
}public static String  _process_globals() throws Exception{
 //BA.debugLineNum = 15;BA.debugLine="Sub Process_Globals";
 //BA.debugLineNum = 16;BA.debugLine="End Sub";
return "";
}
public static String  _showlogin() throws Exception{
 //BA.debugLineNum = 133;BA.debugLine="Sub ShowLogin";
 //BA.debugLineNum = 134;BA.debugLine="pnlLogin.Visible = True";
mostCurrent._pnllogin.setVisible(anywheresoftware.b4a.keywords.Common.True);
 //BA.debugLineNum = 135;BA.debugLine="pnlStudents.Visible = False";
mostCurrent._pnlstudents.setVisible(anywheresoftware.b4a.keywords.Common.False);
 //BA.debugLineNum = 136;BA.debugLine="End Sub";
return "";
}
public static String  _showstudentselection() throws Exception{
 //BA.debugLineNum = 138;BA.debugLine="Sub ShowStudentSelection";
 //BA.debugLineNum = 139;BA.debugLine="pnlLogin.Visible = False";
mostCurrent._pnllogin.setVisible(anywheresoftware.b4a.keywords.Common.False);
 //BA.debugLineNum = 140;BA.debugLine="pnlStudents.Visible = True";
mostCurrent._pnlstudents.setVisible(anywheresoftware.b4a.keywords.Common.True);
 //BA.debugLineNum = 141;BA.debugLine="Log(\"Showing student selection\")";
anywheresoftware.b4a.keywords.Common.LogImpl("3524291","Showing student selection",0);
 //BA.debugLineNum = 142;BA.debugLine="LoadStudents";
_loadstudents();
 //BA.debugLineNum = 145;BA.debugLine="TryRegisterFCM";
_tryregisterfcm();
 //BA.debugLineNum = 146;BA.debugLine="End Sub";
return "";
}
public static String  _tryregisterfcm() throws Exception{
String _phone = "";
String _token = "";
 //BA.debugLineNum = 148;BA.debugLine="Public Sub TryRegisterFCM";
 //BA.debugLineNum = 149;BA.debugLine="Try";
try { //BA.debugLineNum = 151;BA.debugLine="If lblTokenStatus.IsInitialized = False Then";
if (mostCurrent._lbltokenstatus.IsInitialized()==anywheresoftware.b4a.keywords.Common.False) { 
 //BA.debugLineNum = 152;BA.debugLine="Log(\"TryRegisterFCM: UI not ready yet, skipping";
anywheresoftware.b4a.keywords.Common.LogImpl("3589828","TryRegisterFCM: UI not ready yet, skipping",0);
 //BA.debugLineNum = 153;BA.debugLine="Return";
if (true) return "";
 };
 //BA.debugLineNum = 156;BA.debugLine="Dim phone As String = \"\"";
_phone = "";
 //BA.debugLineNum = 157;BA.debugLine="If File.Exists(File.DirInternal, \"parent_phone.t";
if (anywheresoftware.b4a.keywords.Common.File.Exists(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"parent_phone.txt")) { 
 //BA.debugLineNum = 158;BA.debugLine="phone = File.ReadString(File.DirInternal, \"pare";
_phone = anywheresoftware.b4a.keywords.Common.File.ReadString(anywheresoftware.b4a.keywords.Common.File.getDirInternal(),"parent_phone.txt");
 };
 //BA.debugLineNum = 161;BA.debugLine="Dim token As String = CallSub(FirebaseMessaging,";
_token = BA.ObjectToString(anywheresoftware.b4a.keywords.Common.CallSubNew(processBA,(Object)(mostCurrent._firebasemessaging.getObject()),"GetToken"));
 //BA.debugLineNum = 162;BA.debugLine="Log(\"Attempting FCM Registration: Phone=\" & phon";
anywheresoftware.b4a.keywords.Common.LogImpl("3589838","Attempting FCM Registration: Phone="+_phone+", Token="+_token,0);
 //BA.debugLineNum = 165;BA.debugLine="If token <> \"\" And token <> \"null\" And token.Len";
if ((_token).equals("") == false && (_token).equals("null") == false && _token.length()>20) { 
 //BA.debugLineNum = 166;BA.debugLine="lblTokenStatus.Text = \"FCM Status: Registered ✅";
mostCurrent._lbltokenstatus.setText(BA.ObjectToCharSequence("FCM Status: Registered ✅"));
 //BA.debugLineNum = 167;BA.debugLine="lblTokenStatus.TextColor = Colors.RGB(76, 175,";
mostCurrent._lbltokenstatus.setTextColor(anywheresoftware.b4a.keywords.Common.Colors.RGB((int) (76),(int) (175),(int) (80)));
 //BA.debugLineNum = 168;BA.debugLine="If phone <> \"\" Then";
if ((_phone).equals("") == false) { 
 //BA.debugLineNum = 169;BA.debugLine="APIModule.RegisterFCMToken(phone, token)";
mostCurrent._apimodule._registerfcmtoken /*String*/ (mostCurrent.activityBA,_phone,_token);
 };
 }else {
 //BA.debugLineNum = 172;BA.debugLine="lblTokenStatus.Text = \"FCM Status: No Token (Wa";
mostCurrent._lbltokenstatus.setText(BA.ObjectToCharSequence("FCM Status: No Token (Waiting for Google...)"));
 //BA.debugLineNum = 173;BA.debugLine="lblTokenStatus.TextColor = Colors.Red";
mostCurrent._lbltokenstatus.setTextColor(anywheresoftware.b4a.keywords.Common.Colors.Red);
 //BA.debugLineNum = 174;BA.debugLine="Log(\"FCM Registration skipped: token missing or";
anywheresoftware.b4a.keywords.Common.LogImpl("3589850","FCM Registration skipped: token missing or invalid",0);
 };
 } 
       catch (Exception e24) {
			processBA.setLastException(e24); //BA.debugLineNum = 178;BA.debugLine="Log(\"Error in TryRegisterFCM: \" & LastException)";
anywheresoftware.b4a.keywords.Common.LogImpl("3589854","Error in TryRegisterFCM: "+BA.ObjectToString(anywheresoftware.b4a.keywords.Common.LastException(mostCurrent.activityBA)),0);
 };
 //BA.debugLineNum = 181;BA.debugLine="End Sub";
return "";
}
}
