package com.hellocode.service;

import com.hellocode.main.PodCast;
import com.hellocode.model.JDomPodCastURL;
import com.hellocode.util.FileUtil;
import com.hellocode.util.XML2JavaUtil;

public final class RunTime {

	public static String selectedFileName = "";
	private static final String CONFIG_XML = "mead.xml";
	public static boolean synchronizing = false;
	public static Config CONFIG = new Config();
	public static boolean refreshing = false;
	

	public static void resetAll(){
		FileUtil.deleteFile(CONFIG_XML);
	}
	public static void destroy() {
		try {
			for(JDomPodCastURL pod :RunTime.CONFIG.feed_au){
				pod.clearMedia();
			}
			XML2JavaUtil.java2XML(CONFIG_XML, RunTime.CONFIG);
		} catch (Exception e) {
			FileUtil.deleteFile(CONFIG_XML);
		}
		System.out.println("DESTROY");
	}

	public static void init() {

		try {
			CONFIG = XML2JavaUtil.XML2Java(CONFIG_XML);
		} catch (Exception e) {
			e.printStackTrace();
			FileUtil.deleteFile(CONFIG_XML);
			CONFIG = new Config();			
		}
		
		FileUtil.createDir(CONFIG.disk_main);
		// feed_tv.add(url);
	}

	public static JDomPodCastURL findFeedByName(String name) {
		for (JDomPodCastURL pod : RunTime.CONFIG.feed_au) {
			if (pod.getName().equalsIgnoreCase(name)) {
				return pod;
			}
		}
		// throw new RuntimeException();
		return null;
	}

	public static void refreshAll() {
		PodCast.main.lb_info.setText("ڸfeed,Ժ...");
		if (RunTime.CONFIG.feed_au.size() == 0) {
			PodCast.main.lb_info.setText("ûжκfeed,Add Feed. ллʹ");
		}
		if (refreshing) {
			PodCast.main.lb_info.setText("̳߳ͻˢRefresh");
			return;
		}
		
		new Thread(new Runnable() {

			@Override
			public void run() {
				
				synchronized (RunTime.CONFIG.feed_au) {
					refreshing = true;
					try {
						System.out.println("runing...");
						for (JDomPodCastURL pod : RunTime.CONFIG.feed_au) {
							System.out.println("runing...");
							PodCast.main.lb_info.setText(pod.getName() + "ڸ"
									+ pod.getURL());

							pod.reFreshURL();
						}
						PodCast.main.lb_info.setText("ɸ!");
						System.out.println("runing...");
					} catch (Exception e) {
						refreshing = false;
					} finally {
						refreshing = false;
					}
					refreshing = false;
				}
			}
		}).start();
		System.out.println("runing...");
	}

	public static void main(String[] args) {
		// RunTime run = new RunTime();
		System.out.println(RunTime.CONFIG.disk_main);

	}
}

@@ -577,16 +577,81 @@
 %09try %7B%0D%0A
+%09%09%09//clear all the items, do not save to XML configuration file%0D%0A
 %09%09%09for(J
@@ -1679,16 +1679,12 @@
 %22%DF%B3%CC%B3%CD%BB
-%CB%A2Refresh
+%C8%B4%D2%BB%DF%B3%CB%A2
 %22);%0D
@@ -2000,24 +2000,83 @@
 ning...%22);%0D%0A
+%09%09%09%09%09%09%09//PodCast.main.lb_note.setText(%22%DA%B8%22+pod.getName());%0D%0A
 %09%09%09%09%09%09%09PodCa
@@ -2180,24 +2180,74 @@
 ;%0D%0A%09%09%09%09%09%09%7D%0D%0A
+%09%09%09%09%09%09//PodCast.main.lb_note.setText(%22feeds%C9%B8!%22);%0D%0A
 %09%09%09%09%09%09PodCas

Add some flag & mark use ArrayList to save Threads